<!doctype html>
<html>
<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width initial-scale=1'>
    <title>设计模式-day03</title>
    <link href='https://fonts.loli.net/css?family=Open+Sans:400italic,700italic,700,400&subset=latin,latin-ext' rel='stylesheet' type='text/css'/>
    <style type='text/css'>html {
        overflow-x: initial !important;
    }

    :root {
        --bg-color: #ffffff;
        --text-color: #333333;
        --select-text-bg-color: #B5D6FC;
        --select-text-font-color: auto;
        --monospace: "Lucida Console", Consolas, "Courier", monospace;
    }

    html {
        font-size: 14px;
        background-color: var(--bg-color);
        color: var(--text-color);
        font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
        -webkit-font-smoothing: antialiased;
    }

    body {
        margin: 0px;
        padding: 0px;
        height: auto;
        bottom: 0px;
        top: 0px;
        left: 0px;
        right: 0px;
        font-size: 1rem;
        line-height: 1.42857;
        overflow-x: hidden;
        background: inherit;
        tab-size: 4;
    }

    iframe {
        margin: auto;
    }

    a.url {
        word-break: break-all;
    }

    a:active, a:hover {
        outline: 0px;
    }

    .in-text-selection, ::selection {
        text-shadow: none;
        background: var(--select-text-bg-color);
        color: var(--select-text-font-color);
    }

    #write {
        margin: 0px auto;
        height: auto;
        width: inherit;
        word-break: normal;
        overflow-wrap: break-word;
        position: relative;
        white-space: normal;
        overflow-x: visible;
        padding-top: 40px;
    }

    #write.first-line-indent p {
        text-indent: 2em;
    }

    #write.first-line-indent li p, #write.first-line-indent p * {
        text-indent: 0px;
    }

    #write.first-line-indent li {
        margin-left: 2em;
    }

    .for-image #write {
        padding-left: 8px;
        padding-right: 8px;
    }

    body.typora-export {
        padding-left: 30px;
        padding-right: 30px;
    }

    .typora-export .footnote-line, .typora-export li, .typora-export p {
        white-space: pre-wrap;
    }

    @media screen and (max-width: 500px) {
        body.typora-export {
            padding-left: 0px;
            padding-right: 0px;
        }

        #write {
            padding-left: 20px;
            padding-right: 20px;
        }

        .CodeMirror-sizer {
            margin-left: 0px !important;
        }

        .CodeMirror-gutters {
            display: none !important;
        }
    }

    #write li > figure:last-child {
        margin-bottom: 0.5rem;
    }

    #write ol, #write ul {
        position: relative;
    }

    img {
        max-width: 100%;
        vertical-align: middle;
    }

    button, input, select, textarea {
        color: inherit;
        font: inherit;
    }

    input[type="checkbox"], input[type="radio"] {
        line-height: normal;
        padding: 0px;
    }

    *, ::after, ::before {
        box-sizing: border-box;
    }

    #write h1, #write h2, #write h3, #write h4, #write h5, #write h6, #write p, #write pre {
        width: inherit;
    }

    #write h1, #write h2, #write h3, #write h4, #write h5, #write h6, #write p {
        position: relative;
    }

    p {
        line-height: inherit;
    }

    h1, h2, h3, h4, h5, h6 {
        break-after: avoid-page;
        break-inside: avoid;
        orphans: 2;
    }

    p {
        orphans: 4;
    }

    h1 {
        font-size: 2rem;
    }

    h2 {
        font-size: 1.8rem;
    }

    h3 {
        font-size: 1.6rem;
    }

    h4 {
        font-size: 1.4rem;
    }

    h5 {
        font-size: 1.2rem;
    }

    h6 {
        font-size: 1rem;
    }

    .md-math-block, .md-rawblock, h1, h2, h3, h4, h5, h6, p {
        margin-top: 1rem;
        margin-bottom: 1rem;
    }

    .hidden {
        display: none;
    }

    .md-blockmeta {
        color: rgb(204, 204, 204);
        font-weight: 700;
        font-style: italic;
    }

    a {
        cursor: pointer;
    }

    sup.md-footnote {
        padding: 2px 4px;
        background-color: rgba(238, 238, 238, 0.7);
        color: rgb(85, 85, 85);
        border-radius: 4px;
        cursor: pointer;
    }

    sup.md-footnote a, sup.md-footnote a:hover {
        color: inherit;
        text-transform: inherit;
        text-decoration: inherit;
    }

    #write input[type="checkbox"] {
        cursor: pointer;
        width: inherit;
        height: inherit;
    }

    figure {
        overflow-x: auto;
        margin: 1.2em 0px;
        max-width: calc(100% + 16px);
        padding: 0px;
    }

    figure > table {
        margin: 0px !important;
    }

    tr {
        break-inside: avoid;
        break-after: auto;
    }

    thead {
        display: table-header-group;
    }

    table {
        border-collapse: collapse;
        border-spacing: 0px;
        width: 100%;
        overflow: auto;
        break-inside: auto;
        text-align: left;
    }

    table.md-table td {
        min-width: 32px;
    }

    .CodeMirror-gutters {
        border-right: 0px;
        background-color: inherit;
    }

    .CodeMirror-linenumber {
        user-select: none;
    }

    .CodeMirror {
        text-align: left;
    }

    .CodeMirror-placeholder {
        opacity: 0.3;
    }

    .CodeMirror pre {
        padding: 0px 4px;
    }

    .CodeMirror-lines {
        padding: 0px;
    }

    div.hr:focus {
        cursor: none;
    }

    #write pre {
        white-space: pre-wrap;
    }

    #write.fences-no-line-wrapping pre {
        white-space: pre;
    }

    #write pre.ty-contain-cm {
        white-space: normal;
    }

    .CodeMirror-gutters {
        margin-right: 4px;
    }

    .md-fences {
        font-size: 0.9rem;
        display: block;
        break-inside: avoid;
        text-align: left;
        overflow: visible;
        white-space: pre;
        background: inherit;
        position: relative !important;
    }

    .md-diagram-panel {
        width: 100%;
        margin-top: 10px;
        text-align: center;
        padding-top: 0px;
        padding-bottom: 8px;
        overflow-x: auto;
    }

    #write .md-fences.mock-cm {
        white-space: pre-wrap;
    }

    .md-fences.md-fences-with-lineno {
        padding-left: 0px;
    }

    #write.fences-no-line-wrapping .md-fences.mock-cm {
        white-space: pre;
        overflow-x: auto;
    }

    .md-fences.mock-cm.md-fences-with-lineno {
        padding-left: 8px;
    }

    .CodeMirror-line, twitterwidget {
        break-inside: avoid;
    }

    .footnotes {
        opacity: 0.8;
        font-size: 0.9rem;
        margin-top: 1em;
        margin-bottom: 1em;
    }

    .footnotes + .footnotes {
        margin-top: 0px;
    }

    .md-reset {
        margin: 0px;
        padding: 0px;
        border: 0px;
        outline: 0px;
        vertical-align: top;
        background: 0px 0px;
        text-decoration: none;
        text-shadow: none;
        float: none;
        position: static;
        width: auto;
        height: auto;
        white-space: nowrap;
        cursor: inherit;
        -webkit-tap-highlight-color: transparent;
        line-height: normal;
        font-weight: 400;
        text-align: left;
        box-sizing: content-box;
        direction: ltr;
    }

    li div {
        padding-top: 0px;
    }

    blockquote {
        margin: 1rem 0px;
    }

    li .mathjax-block, li p {
        margin: 0.5rem 0px;
    }

    li {
        margin: 0px;
        position: relative;
    }

    blockquote > :last-child {
        margin-bottom: 0px;
    }

    blockquote > :first-child, li > :first-child {
        margin-top: 0px;
    }

    .footnotes-area {
        color: rgb(136, 136, 136);
        margin-top: 0.714rem;
        padding-bottom: 0.143rem;
        white-space: normal;
    }

    #write .footnote-line {
        white-space: pre-wrap;
    }

    @media print {
        body, html {
            border: 1px solid transparent;
            height: 99%;
            break-after: avoid;
            break-before: avoid;
        }

        #write {
            margin-top: 0px;
            padding-top: 0px;
            border-color: transparent !important;
        }

        .typora-export * {
            -webkit-print-color-adjust: exact;
        }

        html.blink-to-pdf {
            font-size: 13px;
        }

        .typora-export #write {
            padding-left: 32px;
            padding-right: 32px;
            padding-bottom: 0px;
            break-after: avoid;
        }

        .typora-export #write::after {
            height: 0px;
        }
    }

    .footnote-line {
        margin-top: 0.714em;
        font-size: 0.7em;
    }

    a img, img a {
        cursor: pointer;
    }

    pre.md-meta-block {
        font-size: 0.8rem;
        min-height: 0.8rem;
        white-space: pre-wrap;
        background: rgb(204, 204, 204);
        display: block;
        overflow-x: hidden;
    }

    p > .md-image:only-child:not(.md-img-error) img, p > img:only-child {
        display: block;
        margin: auto;
    }

    p > .md-image:only-child {
        display: inline-block;
        width: 100%;
    }

    #write .MathJax_Display {
        margin: 0.8em 0px 0px;
    }

    .md-math-block {
        width: 100%;
    }

    .md-math-block:not(:empty)::after {
        display: none;
    }

    [contenteditable="true"]:active, [contenteditable="true"]:focus, [contenteditable="false"]:active, [contenteditable="false"]:focus {
        outline: 0px;
        box-shadow: none;
    }

    .md-task-list-item {
        position: relative;
        list-style-type: none;
    }

    .task-list-item.md-task-list-item {
        padding-left: 0px;
    }

    .md-task-list-item > input {
        position: absolute;
        top: 0px;
        left: 0px;
        margin-left: -1.2em;
        margin-top: calc(1em - 10px);
        border: none;
    }

    .math {
        font-size: 1rem;
    }

    .md-toc {
        min-height: 3.58rem;
        position: relative;
        font-size: 0.9rem;
        border-radius: 10px;
    }

    .md-toc-content {
        position: relative;
        margin-left: 0px;
    }

    .md-toc-content::after, .md-toc::after {
        display: none;
    }

    .md-toc-item {
        display: block;
        color: rgb(65, 131, 196);
    }

    .md-toc-item a {
        text-decoration: none;
    }

    .md-toc-inner:hover {
        text-decoration: underline;
    }

    .md-toc-inner {
        display: inline-block;
        cursor: pointer;
    }

    .md-toc-h1 .md-toc-inner {
        margin-left: 0px;
        font-weight: 700;
    }

    .md-toc-h2 .md-toc-inner {
        margin-left: 2em;
    }

    .md-toc-h3 .md-toc-inner {
        margin-left: 4em;
    }

    .md-toc-h4 .md-toc-inner {
        margin-left: 6em;
    }

    .md-toc-h5 .md-toc-inner {
        margin-left: 8em;
    }

    .md-toc-h6 .md-toc-inner {
        margin-left: 10em;
    }

    @media screen and (max-width: 48em) {
        .md-toc-h3 .md-toc-inner {
            margin-left: 3.5em;
        }

        .md-toc-h4 .md-toc-inner {
            margin-left: 5em;
        }

        .md-toc-h5 .md-toc-inner {
            margin-left: 6.5em;
        }

        .md-toc-h6 .md-toc-inner {
            margin-left: 8em;
        }
    }

    a.md-toc-inner {
        font-size: inherit;
        font-style: inherit;
        font-weight: inherit;
        line-height: inherit;
    }

    .footnote-line a:not(.reversefootnote) {
        color: inherit;
    }

    .md-attr {
        display: none;
    }

    .md-fn-count::after {
        content: ".";
    }

    code, pre, samp, tt {
        font-family: var(--monospace);
    }

    kbd {
        margin: 0px 0.1em;
        padding: 0.1em 0.6em;
        font-size: 0.8em;
        color: rgb(36, 39, 41);
        background: rgb(255, 255, 255);
        border: 1px solid rgb(173, 179, 185);
        border-radius: 3px;
        box-shadow: rgba(12, 13, 14, 0.2) 0px 1px 0px, rgb(255, 255, 255) 0px 0px 0px 2px inset;
        white-space: nowrap;
        vertical-align: middle;
    }

    .md-comment {
        color: rgb(162, 127, 3);
        opacity: 0.8;
        font-family: var(--monospace);
    }

    code {
        text-align: left;
        vertical-align: initial;
    }

    a.md-print-anchor {
        white-space: pre !important;
        border-width: initial !important;
        border-style: none !important;
        border-color: initial !important;
        display: inline-block !important;
        position: absolute !important;
        width: 1px !important;
        right: 0px !important;
        outline: 0px !important;
        background: 0px 0px !important;
        text-decoration: initial !important;
        text-shadow: initial !important;
    }

    .md-inline-math .MathJax_SVG .noError {
        display: none !important;
    }

    .html-for-mac .inline-math-svg .MathJax_SVG {
        vertical-align: 0.2px;
    }

    .md-math-block .MathJax_SVG_Display {
        text-align: center;
        margin: 0px;
        position: relative;
        text-indent: 0px;
        max-width: none;
        max-height: none;
        min-height: 0px;
        min-width: 100%;
        width: auto;
        overflow-y: hidden;
        display: block !important;
    }

    .MathJax_SVG_Display, .md-inline-math .MathJax_SVG_Display {
        width: auto;
        margin: inherit;
        display: inline-block !important;
    }

    .MathJax_SVG .MJX-monospace {
        font-family: var(--monospace);
    }

    .MathJax_SVG .MJX-sans-serif {
        font-family: sans-serif;
    }

    .MathJax_SVG {
        display: inline;
        font-style: normal;
        font-weight: 400;
        line-height: normal;
        zoom: 90%;
        text-indent: 0px;
        text-align: left;
        text-transform: none;
        letter-spacing: normal;
        word-spacing: normal;
        overflow-wrap: normal;
        white-space: nowrap;
        float: none;
        direction: ltr;
        max-width: none;
        max-height: none;
        min-width: 0px;
        min-height: 0px;
        border: 0px;
        padding: 0px;
        margin: 0px;
    }

    .MathJax_SVG * {
        transition: none 0s ease 0s;
    }

    .MathJax_SVG_Display svg {
        vertical-align: middle !important;
        margin-bottom: 0px !important;
        margin-top: 0px !important;
    }

    .os-windows.monocolor-emoji .md-emoji {
        font-family: "Segoe UI Symbol", sans-serif;
    }

    .md-diagram-panel > svg {
        max-width: 100%;
    }

    [lang="flow"] svg, [lang="mermaid"] svg {
        max-width: 100%;
        height: auto;
    }

    [lang="mermaid"] .node text {
        font-size: 1rem;
    }

    table tr th {
        border-bottom: 0px;
    }

    video {
        max-width: 100%;
        display: block;
        margin: 0px auto;
    }

    iframe {
        max-width: 100%;
        width: 100%;
        border: none;
    }

    .highlight td, .highlight tr {
        border: 0px;
    }

    svg[id^="mermaidChart"] {
        line-height: 1em;
    }

    mark {
        background: rgb(255, 255, 0);
        color: rgb(0, 0, 0);
    }

    .md-html-inline .md-plain, .md-html-inline strong, mark .md-inline-math, mark strong {
        color: inherit;
    }

    mark .md-meta {
        color: rgb(0, 0, 0);
        opacity: 0.3 !important;
    }


    .CodeMirror {
        height: auto;
    }

    .CodeMirror.cm-s-inner {
        background: inherit;
    }

    .CodeMirror-scroll {
        overflow: auto hidden;
        z-index: 3;
    }

    .CodeMirror-gutter-filler, .CodeMirror-scrollbar-filler {
        background-color: rgb(255, 255, 255);
    }

    .CodeMirror-gutters {
        border-right: 1px solid rgb(221, 221, 221);
        background: inherit;
        white-space: nowrap;
    }

    .CodeMirror-linenumber {
        padding: 0px 3px 0px 5px;
        text-align: right;
        color: rgb(153, 153, 153);
    }

    .cm-s-inner .cm-keyword {
        color: rgb(119, 0, 136);
    }

    .cm-s-inner .cm-atom, .cm-s-inner.cm-atom {
        color: rgb(34, 17, 153);
    }

    .cm-s-inner .cm-number {
        color: rgb(17, 102, 68);
    }

    .cm-s-inner .cm-def {
        color: rgb(0, 0, 255);
    }

    .cm-s-inner .cm-variable {
        color: rgb(0, 0, 0);
    }

    .cm-s-inner .cm-variable-2 {
        color: rgb(0, 85, 170);
    }

    .cm-s-inner .cm-variable-3 {
        color: rgb(0, 136, 85);
    }

    .cm-s-inner .cm-string {
        color: rgb(170, 17, 17);
    }

    .cm-s-inner .cm-property {
        color: rgb(0, 0, 0);
    }

    .cm-s-inner .cm-operator {
        color: rgb(152, 26, 26);
    }

    .cm-s-inner .cm-comment, .cm-s-inner.cm-comment {
        color: rgb(170, 85, 0);
    }

    .cm-s-inner .cm-string-2 {
        color: rgb(255, 85, 0);
    }

    .cm-s-inner .cm-meta {
        color: rgb(85, 85, 85);
    }

    .cm-s-inner .cm-qualifier {
        color: rgb(85, 85, 85);
    }

    .cm-s-inner .cm-builtin {
        color: rgb(51, 0, 170);
    }

    .cm-s-inner .cm-bracket {
        color: rgb(153, 153, 119);
    }

    .cm-s-inner .cm-tag {
        color: rgb(17, 119, 0);
    }

    .cm-s-inner .cm-attribute {
        color: rgb(0, 0, 204);
    }

    .cm-s-inner .cm-header, .cm-s-inner.cm-header {
        color: rgb(0, 0, 255);
    }

    .cm-s-inner .cm-quote, .cm-s-inner.cm-quote {
        color: rgb(0, 153, 0);
    }

    .cm-s-inner .cm-hr, .cm-s-inner.cm-hr {
        color: rgb(153, 153, 153);
    }

    .cm-s-inner .cm-link, .cm-s-inner.cm-link {
        color: rgb(0, 0, 204);
    }

    .cm-negative {
        color: rgb(221, 68, 68);
    }

    .cm-positive {
        color: rgb(34, 153, 34);
    }

    .cm-header, .cm-strong {
        font-weight: 700;
    }

    .cm-del {
        text-decoration: line-through;
    }

    .cm-em {
        font-style: italic;
    }

    .cm-link {
        text-decoration: underline;
    }

    .cm-error {
        color: red;
    }

    .cm-invalidchar {
        color: red;
    }

    .cm-constant {
        color: rgb(38, 139, 210);
    }

    .cm-defined {
        color: rgb(181, 137, 0);
    }

    div.CodeMirror span.CodeMirror-matchingbracket {
        color: rgb(0, 255, 0);
    }

    div.CodeMirror span.CodeMirror-nonmatchingbracket {
        color: rgb(255, 34, 34);
    }

    .cm-s-inner .CodeMirror-activeline-background {
        background: inherit;
    }

    .CodeMirror {
        position: relative;
        overflow: hidden;
    }

    .CodeMirror-scroll {
        height: 100%;
        outline: 0px;
        position: relative;
        box-sizing: content-box;
        background: inherit;
    }

    .CodeMirror-sizer {
        position: relative;
    }

    .CodeMirror-gutter-filler, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-vscrollbar {
        position: absolute;
        z-index: 6;
        display: none;
    }

    .CodeMirror-vscrollbar {
        right: 0px;
        top: 0px;
        overflow: hidden;
    }

    .CodeMirror-hscrollbar {
        bottom: 0px;
        left: 0px;
        overflow: hidden;
    }

    .CodeMirror-scrollbar-filler {
        right: 0px;
        bottom: 0px;
    }

    .CodeMirror-gutter-filler {
        left: 0px;
        bottom: 0px;
    }

    .CodeMirror-gutters {
        position: absolute;
        left: 0px;
        top: 0px;
        padding-bottom: 30px;
        z-index: 3;
    }

    .CodeMirror-gutter {
        white-space: normal;
        height: 100%;
        box-sizing: content-box;
        padding-bottom: 30px;
        margin-bottom: -32px;
        display: inline-block;
    }

    .CodeMirror-gutter-wrapper {
        position: absolute;
        z-index: 4;
        background: 0px 0px !important;
        border: none !important;
    }

    .CodeMirror-gutter-background {
        position: absolute;
        top: 0px;
        bottom: 0px;
        z-index: 4;
    }

    .CodeMirror-gutter-elt {
        position: absolute;
        cursor: default;
        z-index: 4;
    }

    .CodeMirror-lines {
        cursor: text;
    }

    .CodeMirror pre {
        border-radius: 0px;
        border-width: 0px;
        background: 0px 0px;
        font-family: inherit;
        font-size: inherit;
        margin: 0px;
        white-space: pre;
        overflow-wrap: normal;
        color: inherit;
        z-index: 2;
        position: relative;
        overflow: visible;
    }

    .CodeMirror-wrap pre {
        overflow-wrap: break-word;
        white-space: pre-wrap;
        word-break: normal;
    }

    .CodeMirror-code pre {
        border-right: 30px solid transparent;
        width: fit-content;
    }

    .CodeMirror-wrap .CodeMirror-code pre {
        border-right: none;
        width: auto;
    }

    .CodeMirror-linebackground {
        position: absolute;
        left: 0px;
        right: 0px;
        top: 0px;
        bottom: 0px;
        z-index: 0;
    }

    .CodeMirror-linewidget {
        position: relative;
        z-index: 2;
        overflow: auto;
    }

    .CodeMirror-wrap .CodeMirror-scroll {
        overflow-x: hidden;
    }

    .CodeMirror-measure {
        position: absolute;
        width: 100%;
        height: 0px;
        overflow: hidden;
        visibility: hidden;
    }

    .CodeMirror-measure pre {
        position: static;
    }

    .CodeMirror div.CodeMirror-cursor {
        position: absolute;
        visibility: hidden;
        border-right: none;
        width: 0px;
    }

    .CodeMirror div.CodeMirror-cursor {
        visibility: hidden;
    }

    .CodeMirror-focused div.CodeMirror-cursor {
        visibility: inherit;
    }

    .cm-searching {
        background: rgba(255, 255, 0, 0.4);
    }

    @media print {
        .CodeMirror div.CodeMirror-cursor {
            visibility: hidden;
        }
    }


    :root {
        --side-bar-bg-color: #fafafa;
        --control-text-color: #777;
    }

    @include-when-export url(https://fonts.loli.net/css?family=Open+Sans:400italic,700italic,700,400&subset=latin,latin-ext);

    html {
        font-size: 16px;
    }

    body {
        font-family: "Courier New", "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
        color: rgb(51, 51, 51);
        line-height: 1.6;
    }

    #write {
        max-width: 100%;
        margin: 0 auto;
        padding: 30px;
        padding-bottom: 100px;
    }

    #write > ul:first-child,
    #write > ol:first-child {
        margin-top: 30px;
    }

    a {
        color: #4183C4;
    }

    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
        position: relative;
        margin-top: 1rem;
        margin-bottom: 1rem;
        font-weight: bold;
        line-height: 1.4;
        cursor: text;
    }

    h1:hover a.anchor,
    h2:hover a.anchor,
    h3:hover a.anchor,
    h4:hover a.anchor,
    h5:hover a.anchor,
    h6:hover a.anchor {
        text-decoration: none;
    }

    h1 tt,
    h1 code {
        font-size: inherit;
    }

    h2 tt,
    h2 code {
        font-size: inherit;
    }

    h3 tt,
    h3 code {
        font-size: inherit;
    }

    h4 tt,
    h4 code {
        font-size: inherit;
    }

    h5 tt,
    h5 code {
        font-size: inherit;
    }

    h6 tt,
    h6 code {
        font-size: inherit;
    }

    h1 {
        padding-bottom: .3em;
        font-size: 2.25em;
        line-height: 1.2;
        border-bottom: 1px solid #eee;
    }

    h2 {
        padding-bottom: .3em;
        font-size: 1.75em;
        line-height: 1.225;
        border-bottom: 1px solid #eee;
    }

    h3 {
        font-size: 1.5em;
        line-height: 1.43;
    }

    h4 {
        font-size: 1.25em;
    }

    h5 {
        font-size: 1em;
    }

    h6 {
        font-size: 1em;
        color: #777;
    }

    p,
    blockquote,
    ul,
    ol,
    dl,
    table {
        margin: 0.8em 0;
    }

    li > ol,
    li > ul {
        margin: 0 0;
    }

    hr {
        height: 2px;
        padding: 0;
        margin: 16px 0;
        background-color: #e7e7e7;
        border: 0 none;
        overflow: hidden;
        box-sizing: content-box;
    }

    li p.first {
        display: inline-block;
    }

    ul,
    ol {
        padding-left: 30px;
    }

    ul:first-child,
    ol:first-child {
        margin-top: 0;
    }

    ul:last-child,
    ol:last-child {
        margin-bottom: 0;
    }

    blockquote {
        border-left: 4px solid #dfe2e5;
        padding: 0 15px;
        color: #777777;
    }

    blockquote blockquote {
        padding-right: 0;
    }

    table {
        padding: 0;
        word-break: initial;
    }

    table tr {
        border-top: 1px solid #dfe2e5;
        margin: 0;
        padding: 0;
    }

    table tr:nth-child(2n),
    thead {
        background-color: #f8f8f8;
    }

    table tr th {
        font-weight: bold;
        border: 1px solid #dfe2e5;
        border-bottom: 0;
        margin: 0;
        padding: 6px 13px;
    }

    table tr td {
        border: 1px solid #dfe2e5;
        margin: 0;
        padding: 6px 13px;
    }

    table tr th:first-child,
    table tr td:first-child {
        margin-top: 0;
    }

    table tr th:last-child,
    table tr td:last-child {
        margin-bottom: 0;
    }

    .CodeMirror-lines {
        padding-left: 4px;
    }

    .code-tooltip {
        box-shadow: 0 1px 1px 0 rgba(0, 28, 36, .3);
        border-top: 1px solid #eef2f2;
    }

    .md-fences,
    code,
    tt {
        border: 1px solid #e7eaed;
        background-color: #f8f8f8;
        border-radius: 3px;
        padding: 0;
        padding: 2px 4px 0px 4px;
        font-size: 0.9em;
    }

    code {
        background-color: #f3f4f4;
        padding: 0 2px 0 2px;
    }

    .md-fences {
        margin-bottom: 15px;
        margin-top: 15px;
        padding-top: 8px;
        padding-bottom: 6px;
    }


    .md-task-list-item > input {
        margin-left: -1.3em;
    }

    @media print {
        html {
            font-size: 13px;
        }

        table,
        pre {
            page-break-inside: avoid;
        }

        pre {
            word-wrap: break-word;
        }
    }

    .md-fences {
        background-color: #f8f8f8;
    }

    #write pre.md-meta-block {
        padding: 1rem;
        font-size: 85%;
        line-height: 1.45;
        background-color: #f7f7f7;
        border: 0;
        border-radius: 3px;
        color: #777777;
        margin-top: 0 !important;
    }

    .mathjax-block > .code-tooltip {
        bottom: .375rem;
    }

    .md-mathjax-midline {
        background: #fafafa;
    }

    #write > h3.md-focus:before {
        left: -1.5625rem;
        top: .375rem;
    }

    #write > h4.md-focus:before {
        left: -1.5625rem;
        top: .285714286rem;
    }

    #write > h5.md-focus:before {
        left: -1.5625rem;
        top: .285714286rem;
    }

    #write > h6.md-focus:before {
        left: -1.5625rem;
        top: .285714286rem;
    }

    .md-image > .md-meta {
        /*border: 1px solid #ddd;*/
        border-radius: 3px;
        padding: 2px 0px 0px 4px;
        font-size: 0.9em;
        color: inherit;
    }

    .md-tag {
        color: #a7a7a7;
        opacity: 1;
    }

    .md-toc {
        margin-top: 20px;
        padding-bottom: 20px;
    }

    .sidebar-tabs {
        border-bottom: none;
    }

    #typora-quick-open {
        border: 1px solid #ddd;
        background-color: #f8f8f8;
    }

    #typora-quick-open-item {
        background-color: #FAFAFA;
        border-color: #FEFEFE #e5e5e5 #e5e5e5 #eee;
        border-style: solid;
        border-width: 1px;
    }

    /** focus mode */
    .on-focus-mode blockquote {
        border-left-color: rgba(85, 85, 85, 0.12);
    }

    header, .context-menu, .megamenu-content, footer {
        font-family: "Segoe UI", "Arial", sans-serif;
    }

    .file-node-content:hover .file-node-icon,
    .file-node-content:hover .file-node-open-state {
        visibility: visible;
    }

    .mac-seamless-mode #typora-sidebar {
        background-color: #fafafa;
        background-color: var(--side-bar-bg-color);
    }

    .md-lang {
        color: #b4654d;
    }

    .html-for-mac .context-menu {
        --item-hover-bg-color: #E6F0FE;
    }

    #md-notification .btn {
        border: 0;
    }

    .dropdown-menu .divider {
        border-color: #e5e5e5;
    }

    .ty-preferences .window-content {
        background-color: #fafafa;
    }

    .ty-preferences .nav-group-item.active {
        color: white;
        background: #999;
    }

    .typora-export li, .typora-export p, .typora-export, .footnote-line {
        white-space: normal;
    }
    </style>
</head>
<body class='typora-export os-windows'>
<div id='write' class='is-node'><h1><a name="5结构型模式" class="md-header-anchor"></a><span>5，结构型模式</span></h1>
    <p><span>结构型模式描述如何将类或对象按某种布局组成更大的结构。它分为类结构型模式和对象结构型模式，前者采用继承机制来组织接口和类，后者釆用组合或聚合来组合对象。</span></p>
    <p><span>由于组合关系或聚合关系比继承关系耦合度低，满足“合成复用原则”，所以对象结构型模式比类结构型模式具有更大的灵活性。</span></p>
    <p><span>结构型模式分为以下 7 种：</span></p>
    <ul>
        <li><span>代理模式</span></li>
        <li><span>适配器模式</span></li>
        <li><span>装饰者模式</span></li>
        <li><span>桥接模式</span></li>
        <li><span>外观模式</span></li>
        <li><span>组合模式</span></li>
        <li><span>享元模式</span></li>
    </ul>
    <p>&nbsp;</p>
    <h2><a name="51-代理模式" class="md-header-anchor"></a><span>5.1 代理模式</span></h2>
    <h3><a name="511-概述" class="md-header-anchor"></a><span>5.1.1 概述</span></h3>
    <p><span>由于某些原因需要给某对象提供一个代理以控制对该对象的访问。这时，访问对象不适合或者不能直接引用目标对象，代理对象作为访问对象和目标对象之间的中介。</span></p>
    <p><span>Java中的代理按照代理类生成时机不同又分为静态代理和动态代理。静态代理代理类在编译期就生成，而动态代理代理类则是在Java运行时动态生成。动态代理又有JDK代理和CGLib代理两种。</span></p>
    <h3><a name="512-结构" class="md-header-anchor"></a><span>5.1.2 结构</span></h3>
    <p><span>代理（Proxy）模式分为三种角色：</span></p>
    <ul>
        <li><span>抽象主题（Subject）类： 通过接口或抽象类声明真实主题和代理对象实现的业务方法。</span></li>
        <li><span>真实主题（Real Subject）类： 实现了抽象主题中的具体业务，是代理对象所代表的真实对象，是最终要引用的对象。</span></li>
        <li><span>代理（Proxy）类 ： 提供了与真实主题相同的接口，其内部含有对真实主题的引用，它可以访问、控制或扩展真实主题的功能。</span></li>
    </ul>
    <h3><a name="513-静态代理" class="md-header-anchor"></a><span>5.1.3 静态代理</span></h3>
    <p><span>我们通过案例来感受一下静态代理。</span></p>
    <p><span>【例】火车站卖票</span></p>
    <p>
        <span>如果要买火车票的话，需要去火车站买票，坐车到火车站，排队等一系列的操作，显然比较麻烦。而火车站在多个地方都有代售点，我们去代售点买票就方便很多了。这个例子其实就是典型的代理模式，火车站是目标对象，代售点是代理对象。类图如下：</span>
    </p>
    <p><img src="img\静态代理.png" style="zoom:80%;"/></p>
    <p><span>代码如下：</span></p>
    <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="java" style="break-inside: unset;"><div
            class="CodeMirror cm-s-inner CodeMirror-wrap" lang="java"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 44px;"><textarea
            autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0"
            style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler"
                                                                                                                                     cm-not-content="true"></div><div
            class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer"
                                                                                                                           style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div
            style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div
            class="CodeMirror-measure"><span><span>​</span>x</span></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code"
                                                                                                                                                                       role="presentation"
                                                                                                                                                                       style=""><div
            class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div
            class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -36px; width: 36px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter"
                                                                                                                           style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">1</div></div><pre class=" CodeMirror-line "
                                                                                                                                             role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            class="cm-comment">//卖票接口</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"><span
            class="cm-keyword">public</span> <span class="cm-keyword">interface</span> <span class="cm-def">SellTickets</span> {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-variable-3">void</span> <span
            class="cm-variable">sell</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;">}</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                         style="left: 0px; width: 27px;">5</div></div><pre class=" CodeMirror-line "
                                                                                                                                                           role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"><span
            class="cm-comment">//火车站  火车站具有卖票功能，所以需要实现SellTickets接口</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                       style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"><span
            class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span class="cm-def">TrainStation</span> <span class="cm-keyword">implements</span> <span
            class="cm-variable">SellTickets</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"><span
            cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-variable-3">void</span> <span class="cm-variable">sell</span>() {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                        style="left: 0px; width: 27px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span
            class="cm-variable">println</span>(<span class="cm-string">"火车站卖票"</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                     style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">12</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">13</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">14</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//代售点</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">15</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
            class="cm-def">ProxyPoint</span> <span class="cm-keyword">implements</span> <span class="cm-variable">SellTickets</span> {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">16</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">17</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">private</span> <span
            class="cm-variable">TrainStation</span> <span class="cm-variable">station</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">TrainStation</span>();</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">18</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">19</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable-3">void</span> <span class="cm-variable">sell</span>() {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">20</div></div><pre class=" CodeMirror-line "
                                                                                                                                              role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span
            class="cm-string">"代理点收取一些服务费用"</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">21</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">station</span>.<span class="cm-variable">sell</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">22</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">23</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">24</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">25</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//测试类</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">26</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
            class="cm-def">Client</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">27</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-keyword">static</span> <span class="cm-variable-3">void</span> <span class="cm-variable">main</span>(<span class="cm-variable-3">String</span>[] <span
            class="cm-variable">args</span>) {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">28</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">ProxyPoint</span> <span class="cm-variable">pp</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">ProxyPoint</span>();</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">29</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">pp</span>.<span
            class="cm-variable">sell</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">30</div></div><pre class=" CodeMirror-line "
                                                                                                                                              role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 27px;">31</div></div><pre class=" CodeMirror-line "
                                                                                                                                                            role="presentation"><span
            role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div
            style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 703px;"></div><div class="CodeMirror-gutters" style="height: 703px;"><div
            class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div></div></div></div></pre>
    <p><span>从上面代码中可以看出测试类直接访问的是ProxyPoint类对象，也就是说ProxyPoint作为访问对象和目标对象的中介。同时也对sell方法进行了增强（代理点收取一些服务费用）。</span></p>
    <h3><a name="514-jdk动态代理" class="md-header-anchor"></a><span>5.1.4 JDK动态代理</span></h3>
    <p>
        <span>接下来我们使用动态代理实现上面案例，先说说JDK提供的动态代理。Java中提供了一个动态代理类Proxy，Proxy并不是我们上述所说的代理对象的类，而是提供了一个创建代理对象的静态方法（newProxyInstance方法）来获取代理对象。</span>
    </p>
    <p><span>代码如下：</span></p>
    <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="java" style="break-inside: unset;"><div
            class="CodeMirror cm-s-inner CodeMirror-wrap" lang="java"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 44px;"><textarea
            autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0"
            style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler"
                                                                                                                                     cm-not-content="true"></div><div
            class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer"
                                                                                                                           style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div
            style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div
            class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>57</div></div></div><div
            class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline"
                                                                                                                                                               style="position: relative;"><div
            class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter"
                                                                                          style="left: -36px; width: 36px;"></div><div
            class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                     style="left: 0px; width: 27px;">1</div></div><pre class=" CodeMirror-line "
                                                                                                                                                       role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//卖票接口</span></span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span
            class="cm-keyword">interface</span> <span class="cm-def">SellTickets</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                  style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-variable-3">void</span> <span class="cm-variable">sell</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                               style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;">}</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                         style="left: 0px; width: 27px;">5</div></div><pre class=" CodeMirror-line "
                                                                                                                                                           role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"><span
            class="cm-comment">//火车站  火车站具有卖票功能，所以需要实现SellTickets接口</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                       style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"><span
            class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span class="cm-def">TrainStation</span> <span class="cm-keyword">implements</span> <span
            class="cm-variable">SellTickets</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"><span
            cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-variable-3">void</span> <span class="cm-variable">sell</span>() {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                        style="left: 0px; width: 27px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span
            class="cm-variable">println</span>(<span class="cm-string">"火车站卖票"</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                     style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">12</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">13</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">14</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span
            class="cm-comment">//代理工厂，用来创建代理对象</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">15</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span class="cm-def">ProxyFactory</span> {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">16</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">17</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">private</span> <span
            class="cm-variable">TrainStation</span> <span class="cm-variable">station</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">TrainStation</span>();</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">18</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">19</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable">SellTickets</span> <span class="cm-variable">getProxyObject</span>() {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                        style="left: 0px; width: 27px;">20</div></div><pre class=" CodeMirror-line " role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-comment">//使用Proxy获取代理对象</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">21</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-comment">/*</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">22</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-comment">newProxyInstance()方法参数说明：</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">23</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">ClassLoader loader ： 类加载器，用于加载代理类，使用真实对象的类加载器即可</span></span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">24</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">Class&lt;?&gt;[] interfaces ： 真实对象所实现的接口，代理模式真实对象和代理对象实现相同的接口</span></span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">25</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">InvocationHandler h ： 代理对象的调用处理程序</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                           style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">26</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; <span
            class="cm-comment">*/</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">27</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">SellTickets</span> <span class="cm-variable">sellTickets</span> <span class="cm-operator">=</span> (<span class="cm-variable">SellTickets</span>) <span
            class="cm-variable">Proxy</span>.<span class="cm-variable">newProxyInstance</span>(<span class="cm-variable">station</span>.<span class="cm-variable">getClass</span>().<span
            class="cm-variable">getClassLoader</span>(),</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">28</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">station</span>.<span class="cm-variable">getClass</span>().<span class="cm-variable">getInterfaces</span>(),</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">29</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-keyword">new</span> <span class="cm-variable">InvocationHandler</span>() {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                         style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">30</div></div><pre class=" CodeMirror-line "
                                                                                                                                              role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">/*</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">31</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">InvocationHandler中invoke方法参数说明：</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">32</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">proxy ： 代理对象</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">33</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">method ： 对应于在代理对象上调用的接口方法的 Method 实例</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                      style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">34</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">args ： 代理对象调用接口方法时传递的实际参数</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                          style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">35</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
            class="cm-comment">*/</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">36</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-variable-3">Object</span> <span class="cm-variable">invoke</span>(<span class="cm-variable-3">Object</span> <span
            class="cm-variable">proxy</span>, <span class="cm-variable">Method</span> <span class="cm-variable">method</span>, <span class="cm-variable-3">Object</span>[] <span
            class="cm-variable">args</span>) <span class="cm-keyword">throws</span> <span class="cm-variable">Throwable</span> {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">37</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">38</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span
            class="cm-string">"代理点收取一些服务费用(JDK动态代理方式)"</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                         style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">39</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">//执行真实对象</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">40</div></div><pre class=" CodeMirror-line "
                                                                                                                                              role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable-3">Object</span> <span class="cm-variable">result</span> <span class="cm-operator">=</span> <span class="cm-variable">method</span>.<span class="cm-variable">invoke</span>(<span
            class="cm-variable">station</span>, <span class="cm-variable">args</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">41</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-keyword">return</span> <span class="cm-variable">result</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                              style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">42</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">43</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  });</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">44</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">return</span> <span
            class="cm-variable">sellTickets</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">45</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">46</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">47</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">48</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//测试类</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">49</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
            class="cm-def">Client</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">50</div></div><pre class=" CodeMirror-line "
                                                                                                                                              role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-keyword">static</span> <span class="cm-variable-3">void</span> <span class="cm-variable">main</span>(<span class="cm-variable-3">String</span>[] <span
            class="cm-variable">args</span>) {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">51</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">//获取代理对象</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">52</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">ProxyFactory</span> <span class="cm-variable">factory</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">ProxyFactory</span>();</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">53</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">54</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">SellTickets</span> <span class="cm-variable">proxyObject</span> <span class="cm-operator">=</span> <span class="cm-variable">factory</span>.<span
            class="cm-variable">getProxyObject</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">55</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">proxyObject</span>.<span class="cm-variable">sell</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                    style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">56</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 27px;">57</div></div><pre class=" CodeMirror-line "
                                                                                                                                                            role="presentation"><span
            role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div
            style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 1315px;"></div><div class="CodeMirror-gutters" style="height: 1315px;"><div
            class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div></div></div></div></pre>
    <p><font color="red"><span>使用了动态代理，我们思考下面问题：</span></font></p>
    <ul>
        <li><p><span>ProxyFactory是代理类吗？</span></p>
            <p><span>ProxyFactory不是代理模式中所说的代理类，而代理类是程序在运行过程中动态的在内存中生成的类。通过阿里巴巴开源的 Java 诊断工具（Arthas【阿尔萨斯】）查看代理类的结构：</span></p>
            <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="java" style="break-inside: unset;"><div
                    class="CodeMirror cm-s-inner CodeMirror-wrap" lang="java"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 44px;"><textarea
                    autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0"
                    style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler"
                                                                                                                                             cm-not-content="true"></div><div
                    class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer"
                                                                                                                                   style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div
                    style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div
                    class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>83</div></div></div><div
                    class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div
                    class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div
                    class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -36px; width: 36px;"></div><div
                    class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                             style="left: 0px; width: 27px;">1</div></div><pre class=" CodeMirror-line "
                                                                                                                                                               role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">package</span> <span class="cm-def">com</span>.<span class="cm-variable">sun</span>.<span
                    class="cm-variable">proxy</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                        style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">import</span> <span class="cm-variable">com</span>.<span
                    class="cm-variable">itheima</span>.<span class="cm-variable">proxy</span>.<span class="cm-variable">dynamic</span>.<span class="cm-variable">jdk</span>.<span
                    class="cm-variable">SellTickets</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">import</span> <span class="cm-variable">java</span>.<span class="cm-variable">lang</span>.<span
                    class="cm-variable">reflect</span>.<span class="cm-variable">InvocationHandler</span>;</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">5</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">import</span> <span class="cm-variable">java</span>.<span
                    class="cm-variable">lang</span>.<span class="cm-variable">reflect</span>.<span class="cm-variable">Method</span>;</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">import</span> <span class="cm-variable">java</span>.<span
                    class="cm-variable">lang</span>.<span class="cm-variable">reflect</span>.<span class="cm-variable">Proxy</span>;</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">import</span> <span class="cm-variable">java</span>.<span
                    class="cm-variable">lang</span>.<span class="cm-variable">reflect</span>.<span class="cm-variable">UndeclaredThrowableException</span>;</span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                                 style="left: 0px; width: 27px;">8</div></div><pre class=" CodeMirror-line "
                                                                                                                                                                   role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                        style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">final</span> <span class="cm-keyword">class</span> <span
                    class="cm-def">$Proxy0</span> <span class="cm-keyword">extends</span> <span class="cm-variable">Proxy</span> <span class="cm-keyword">implements</span> <span
                    class="cm-variable">SellTickets</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">10</div></div><pre class=" CodeMirror-line "
                                                                                                                                                      role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">private</span> <span class="cm-keyword">static</span> <span class="cm-variable">Method</span> <span
                    class="cm-variable">m1</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">private</span> <span class="cm-keyword">static</span> <span class="cm-variable">Method</span> <span
                    class="cm-variable">m2</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">private</span> <span class="cm-keyword">static</span> <span class="cm-variable">Method</span> <span
                    class="cm-variable">m3</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">private</span> <span class="cm-keyword">static</span> <span class="cm-variable">Method</span> <span
                    class="cm-variable">m0</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                        style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">15</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span class="cm-variable">$Proxy0</span>(<span class="cm-variable">InvocationHandler</span> <span
                    class="cm-variable">invocationHandler</span>) {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">16</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">super</span>(<span
                    class="cm-variable">invocationHandler</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">17</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                         style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">18</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                        style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">19</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">static</span> {</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                style="left: 0px; width: 27px;">20</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">try</span> {</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">21</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">m1</span> <span
                    class="cm-operator">=</span> <span class="cm-variable">Class</span>.<span class="cm-variable">forName</span>(<span class="cm-string">"java.lang.Object"</span>).<span
                    class="cm-variable">getMethod</span>(<span class="cm-string">"equals"</span>, <span class="cm-variable">Class</span>.<span class="cm-variable">forName</span>(<span
                    class="cm-string">"java.lang.Object"</span>));</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">22</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">m2</span> <span class="cm-operator">=</span> <span
                    class="cm-variable">Class</span>.<span class="cm-variable">forName</span>(<span class="cm-string">"java.lang.Object"</span>).<span
                    class="cm-variable">getMethod</span>(<span class="cm-string">"toString"</span>, <span class="cm-keyword">new</span> <span class="cm-variable">Class</span>[<span
                    class="cm-number">0</span>]);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">23</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">m3</span> <span class="cm-operator">=</span> <span
                    class="cm-variable">Class</span>.<span class="cm-variable">forName</span>(<span class="cm-string">"com.itheima.proxy.dynamic.jdk.SellTickets"</span>).<span
                    class="cm-variable">getMethod</span>(<span class="cm-string">"sell"</span>, <span class="cm-keyword">new</span> <span class="cm-variable">Class</span>[<span
                    class="cm-number">0</span>]);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">24</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">m0</span> <span class="cm-operator">=</span> <span
                    class="cm-variable">Class</span>.<span class="cm-variable">forName</span>(<span class="cm-string">"java.lang.Object"</span>).<span
                    class="cm-variable">getMethod</span>(<span class="cm-string">"hashCode"</span>, <span class="cm-keyword">new</span> <span class="cm-variable">Class</span>[<span
                    class="cm-number">0</span>]);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">25</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">return</span>;</span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                                 style="left: 0px; width: 27px;">26</div></div><pre class=" CodeMirror-line "
                                                                                                                                                                    role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                       style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">27</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">catch</span> (<span
                    class="cm-variable">NoSuchMethodException</span> <span class="cm-variable">noSuchMethodException</span>) {</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">28</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">throw</span> <span
                    class="cm-keyword">new</span> <span class="cm-variable">NoSuchMethodError</span>(<span class="cm-variable">noSuchMethodException</span>.<span class="cm-variable">getMessage</span>());</span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                                 style="left: 0px; width: 27px;">29</div></div><pre class=" CodeMirror-line "
                                                                                                                                                                    role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                       style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">30</div></div><pre class=" CodeMirror-line "
                                                                                                                                                      role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">catch</span> (<span
                    class="cm-variable">ClassNotFoundException</span> <span class="cm-variable">classNotFoundException</span>) {</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">31</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">throw</span> <span
                    class="cm-keyword">new</span> <span class="cm-variable">NoClassDefFoundError</span>(<span class="cm-variable">classNotFoundException</span>.<span class="cm-variable">getMessage</span>());</span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                                 style="left: 0px; width: 27px;">32</div></div><pre class=" CodeMirror-line "
                                                                                                                                                                    role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                       style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">33</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                         style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">34</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                        style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">35</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span class="cm-keyword">final</span> <span class="cm-variable-3">boolean</span> <span
                    class="cm-variable">equals</span>(<span class="cm-variable-3">Object</span> <span class="cm-variable">object</span>) {</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">36</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
                    class="cm-keyword">try</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">37</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">return</span> (<span
                    class="cm-variable-3">Boolean</span>)<span class="cm-keyword">this</span>.<span class="cm-variable">h</span>.<span class="cm-variable">invoke</span>(<span
                    class="cm-keyword">this</span>, <span class="cm-variable">m1</span>, <span class="cm-keyword">new</span> <span class="cm-variable-3">Object</span>[]{<span
                    class="cm-variable">object</span>});</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">38</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                       style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">39</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">catch</span> (<span class="cm-variable">Error</span> <span
                    class="cm-operator">|</span> <span class="cm-variable">RuntimeException</span> <span class="cm-variable">throwable</span>) {</span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">40</div></div><pre class=" CodeMirror-line "
                                                                                                                                                      role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">throw</span> <span
                    class="cm-variable">throwable</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">41</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                       style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">42</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">catch</span> (<span class="cm-variable">Throwable</span> <span
                    class="cm-variable">throwable</span>) {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">43</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">throw</span> <span
                    class="cm-keyword">new</span> <span class="cm-variable">UndeclaredThrowableException</span>(<span class="cm-variable">throwable</span>);</span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                                 style="left: 0px; width: 27px;">44</div></div><pre class=" CodeMirror-line "
                                                                                                                                                                    role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                       style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">45</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                         style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">46</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                        style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">47</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span class="cm-keyword">final</span> <span class="cm-variable-3">String</span> <span
                    class="cm-variable">toString</span>() {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">48</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">try</span> {</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">49</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">return</span> (<span
                    class="cm-variable-3">String</span>)<span class="cm-keyword">this</span>.<span class="cm-variable">h</span>.<span class="cm-variable">invoke</span>(<span
                    class="cm-keyword">this</span>, <span class="cm-variable">m2</span>, <span class="cm-atom">null</span>);</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                style="left: 0px; width: 27px;">50</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                       style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">51</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">catch</span> (<span class="cm-variable">Error</span> <span
                    class="cm-operator">|</span> <span class="cm-variable">RuntimeException</span> <span class="cm-variable">throwable</span>) {</span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                                 style="left: 0px; width: 27px;">52</div></div><pre class=" CodeMirror-line "
                                                                                                                                                                    role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">throw</span> <span
                    class="cm-variable">throwable</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">53</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                       style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">54</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">catch</span> (<span class="cm-variable">Throwable</span> <span
                    class="cm-variable">throwable</span>) {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">55</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">throw</span> <span
                    class="cm-keyword">new</span> <span class="cm-variable">UndeclaredThrowableException</span>(<span class="cm-variable">throwable</span>);</span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                                 style="left: 0px; width: 27px;">56</div></div><pre class=" CodeMirror-line "
                                                                                                                                                                    role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                       style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">57</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                         style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">58</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                        style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">59</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span class="cm-keyword">final</span> <span class="cm-variable-3">int</span> <span
                    class="cm-variable">hashCode</span>() {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">60</div></div><pre class=" CodeMirror-line "
                                                                                                                                                      role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">try</span> {</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">61</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">return</span> (<span
                    class="cm-variable-3">Integer</span>)<span class="cm-keyword">this</span>.<span class="cm-variable">h</span>.<span class="cm-variable">invoke</span>(<span
                    class="cm-keyword">this</span>, <span class="cm-variable">m0</span>, <span class="cm-atom">null</span>);</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">62</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  }</span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                                 style="left: 0px; width: 27px;">63</div></div><pre class=" CodeMirror-line "
                                                                                                                                                                    role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">catch</span> (<span class="cm-variable">Error</span> <span
                    class="cm-operator">|</span> <span class="cm-variable">RuntimeException</span> <span class="cm-variable">throwable</span>) {</span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                                 style="left: 0px; width: 27px;">64</div></div><pre class=" CodeMirror-line "
                                                                                                                                                                    role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">throw</span> <span
                    class="cm-variable">throwable</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">65</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                       style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">66</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">catch</span> (<span class="cm-variable">Throwable</span> <span
                    class="cm-variable">throwable</span>) {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">67</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">throw</span> <span
                    class="cm-keyword">new</span> <span class="cm-variable">UndeclaredThrowableException</span>(<span class="cm-variable">throwable</span>);</span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                                 style="left: 0px; width: 27px;">68</div></div><pre class=" CodeMirror-line "
                                                                                                                                                                    role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                       style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">69</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                         style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">70</div></div><pre class=" CodeMirror-line "
                                                                                                                                                      role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                        style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">71</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span class="cm-keyword">final</span> <span class="cm-variable-3">void</span> <span
                    class="cm-variable">sell</span>() {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">72</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">try</span> {</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">73</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">this</span>.<span
                    class="cm-variable">h</span>.<span class="cm-variable">invoke</span>(<span class="cm-keyword">this</span>, <span class="cm-variable">m3</span>, <span
                    class="cm-atom">null</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">74</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">return</span>;</span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                                 style="left: 0px; width: 27px;">75</div></div><pre class=" CodeMirror-line "
                                                                                                                                                                    role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                       style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">76</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">catch</span> (<span class="cm-variable">Error</span> <span
                    class="cm-operator">|</span> <span class="cm-variable">RuntimeException</span> <span class="cm-variable">throwable</span>) {</span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                                 style="left: 0px; width: 27px;">77</div></div><pre class=" CodeMirror-line "
                                                                                                                                                                    role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">throw</span> <span
                    class="cm-variable">throwable</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">78</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                       style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">79</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">catch</span> (<span class="cm-variable">Throwable</span> <span
                    class="cm-variable">throwable</span>) {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">80</div></div><pre class=" CodeMirror-line "
                                                                                                                                                      role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">throw</span> <span
                    class="cm-keyword">new</span> <span class="cm-variable">UndeclaredThrowableException</span>(<span class="cm-variable">throwable</span>);</span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                                 style="left: 0px; width: 27px;">81</div></div><pre class=" CodeMirror-line "
                                                                                                                                                                    role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                       style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">82</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                         style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">83</div></div><pre class=" CodeMirror-line "
                                                                                                                                                      role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div
                    style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 1927px;"></div><div class="CodeMirror-gutters" style="height: 1927px;"><div
                    class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div></div></div></div></pre>
            <p><span>从上面的类中，我们可以看到以下几个信息：</span></p>
            <ul>
                <li><span>代理类（$Proxy0）实现了SellTickets。这也就印证了我们之前说的真实类和代理类实现同样的接口。</span></li>
                <li><span>代理类（$Proxy0）将我们提供了的匿名内部类对象传递给了父类。</span></li>
            </ul>
        </li>
        <li><p><span>动态代理的执行流程是什么样？</span></p>
            <p><span>下面是摘取的重点代码：</span></p>
            <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="java" style="break-inside: unset;"><div
                    class="CodeMirror cm-s-inner CodeMirror-wrap" lang="java"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 44px;"><textarea
                    autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0"
                    style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler"
                                                                                                                                             cm-not-content="true"></div><div
                    class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer"
                                                                                                                                   style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div
                    style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div
                    class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>57</div></div></div><div
                    class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div
                    class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div
                    class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -36px; width: 36px;"></div><div
                    class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                             style="left: 0px; width: 27px;">1</div></div><pre class=" CodeMirror-line "
                                                                                                                                                               role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//程序运行过程中动态生成的代理类</span></span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">final</span> <span
                    class="cm-keyword">class</span> <span class="cm-def">$Proxy0</span> <span class="cm-keyword">extends</span> <span class="cm-variable">Proxy</span> <span
                    class="cm-keyword">implements</span> <span class="cm-variable">SellTickets</span> {</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">private</span> <span
                    class="cm-keyword">static</span> <span class="cm-variable">Method</span> <span class="cm-variable">m3</span>;</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">4</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                                 style="left: 0px; width: 27px;">5</div></div><pre class=" CodeMirror-line "
                                                                                                                                                                   role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span class="cm-variable">$Proxy0</span>(<span class="cm-variable">InvocationHandler</span> <span
                    class="cm-variable">invocationHandler</span>) {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">super</span>(<span
                    class="cm-variable">invocationHandler</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                         style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                        style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">static</span> {</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                style="left: 0px; width: 27px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">m3</span> <span class="cm-operator">=</span> <span
                    class="cm-variable">Class</span>.<span class="cm-variable">forName</span>(<span class="cm-string">"com.itheima.proxy.dynamic.jdk.SellTickets"</span>).<span
                    class="cm-variable">getMethod</span>(<span class="cm-string">"sell"</span>, <span class="cm-keyword">new</span> <span class="cm-variable">Class</span>[<span
                    class="cm-number">0</span>]);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                         style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                        style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span class="cm-keyword">final</span> <span class="cm-variable-3">void</span> <span
                    class="cm-variable">sell</span>() {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">this</span>.<span class="cm-variable">h</span>.<span
                    class="cm-variable">invoke</span>(<span class="cm-keyword">this</span>, <span class="cm-variable">m3</span>, <span class="cm-atom">null</span>);</span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                                 style="left: 0px; width: 27px;">15</div></div><pre class=" CodeMirror-line "
                                                                                                                                                                    role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                         style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">16</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">17</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                        style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">18</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//Java提供的动态代理相关类</span></span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">19</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
                    class="cm-def">Proxy</span> <span class="cm-keyword">implements</span> <span class="cm-variable">java</span>.<span class="cm-variable">io</span>.<span
                    class="cm-variable">Serializable</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">20</div></div><pre class=" CodeMirror-line "
                                                                                                                                                      role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-keyword">protected</span> <span
                    class="cm-variable">InvocationHandler</span> <span class="cm-variable">h</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                             style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">21</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span> </span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">22</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation"
                                                                                                                                cm-text="	">    </span><span
                    class="cm-keyword">protected</span> <span class="cm-variable">Proxy</span>(<span class="cm-variable">InvocationHandler</span> <span class="cm-variable">h</span>) {</span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                                 style="left: 0px; width: 27px;">23</div></div><pre class=" CodeMirror-line "
                                                                                                                                                                    role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">this</span>.<span class="cm-variable">h</span> <span
                    class="cm-operator">=</span> <span class="cm-variable">h</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                             style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">24</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                         style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">25</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">26</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                        style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">27</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//代理工厂类</span></span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">28</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
                    class="cm-def">ProxyFactory</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">29</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                        style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">30</div></div><pre class=" CodeMirror-line "
                                                                                                                                                      role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">private</span> <span class="cm-variable">TrainStation</span> <span
                    class="cm-variable">station</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span
                    class="cm-variable">TrainStation</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">31</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                        style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">32</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span class="cm-variable">SellTickets</span> <span
                    class="cm-variable">getProxyObject</span>() {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">33</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">SellTickets</span> <span
                    class="cm-variable">sellTickets</span> <span class="cm-operator">=</span> (<span class="cm-variable">SellTickets</span>) <span class="cm-variable">Proxy</span>.<span
                    class="cm-variable">newProxyInstance</span>(<span class="cm-variable">station</span>.<span class="cm-variable">getClass</span>().<span
                    class="cm-variable">getClassLoader</span>(),</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">34</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">station</span>.<span
                    class="cm-variable">getClass</span>().<span class="cm-variable">getInterfaces</span>(),</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">35</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
                    class="cm-keyword">new</span> <span class="cm-variable">InvocationHandler</span>() {</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">36</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                                 style="left: 0px; width: 27px;">37</div></div><pre class=" CodeMirror-line "
                                                                                                                                                                    role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
                    class="cm-variable-3">Object</span> <span class="cm-variable">invoke</span>(<span class="cm-variable-3">Object</span> <span class="cm-variable">proxy</span>, <span
                    class="cm-variable">Method</span> <span class="cm-variable">method</span>, <span class="cm-variable-3">Object</span>[] <span class="cm-variable">args</span>) <span
                    class="cm-keyword">throws</span> <span class="cm-variable">Throwable</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                          style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">38</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                        style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">39</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
                    class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span
                    class="cm-string">"代理点收取一些服务费用(JDK动态代理方式)"</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                 style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">40</div></div><pre class=" CodeMirror-line "
                                                                                                                                                      role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
                    class="cm-variable-3">Object</span> <span class="cm-variable">result</span> <span class="cm-operator">=</span> <span class="cm-variable">method</span>.<span
                    class="cm-variable">invoke</span>(<span class="cm-variable">station</span>, <span class="cm-variable">args</span>);</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">41</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
                    class="cm-keyword">return</span> <span class="cm-variable">result</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                      style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">42</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">43</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  });</span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                                 style="left: 0px; width: 27px;">44</div></div><pre class=" CodeMirror-line "
                                                                                                                                                                    role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">return</span> <span class="cm-variable">sellTickets</span>;</span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                                 style="left: 0px; width: 27px;">45</div></div><pre class=" CodeMirror-line "
                                                                                                                                                                    role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                         style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">46</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">47</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                        style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">48</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                        style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">49</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//测试访问类</span></span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                style="left: 0px; width: 27px;">50</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span class="cm-def">Client</span> {</span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                                 style="left: 0px; width: 27px;">51</div></div><pre class=" CodeMirror-line "
                                                                                                                                                                    role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span class="cm-keyword">static</span> <span class="cm-variable-3">void</span> <span
                    class="cm-variable">main</span>(<span class="cm-variable-3">String</span>[] <span class="cm-variable">args</span>) {</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">52</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
                    class="cm-comment">//获取代理对象</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">53</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">ProxyFactory</span> <span class="cm-variable">factory</span> <span
                    class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">ProxyFactory</span>();</span></pre></div><div style="position: relative;"><div
                    class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">54</div></div><pre
                    class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
                    class="cm-variable">SellTickets</span> <span class="cm-variable">proxyObject</span> <span class="cm-operator">=</span> <span class="cm-variable">factory</span>.<span
                    class="cm-variable">getProxyObject</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">55</div></div><pre class=" CodeMirror-line " role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">proxyObject</span>.<span class="cm-variable">sell</span>();</span></pre></div><div
                    style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                                 style="left: 0px; width: 27px;">56</div></div><pre class=" CodeMirror-line "
                                                                                                                                                                    role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                         style="left: -36px;"><div
                    class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">57</div></div><pre class=" CodeMirror-line "
                                                                                                                                                      role="presentation"><span
                    role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div
                    style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 1360px;"></div><div class="CodeMirror-gutters" style="height: 1360px;"><div
                    class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div></div></div></div></pre>
        </li>
    </ul>
    <p><span>执行流程如下：</span></p>
    <ol start=''>
        <li><span>在测试类中通过代理对象调用sell()方法</span></li>
        <li><span>根据多态的特性，执行的是代理类（$Proxy0）中的sell()方法</span></li>
        <li><span>代理类（$Proxy0）中的sell()方法中又调用了InvocationHandler接口的子实现类对象的invoke方法</span></li>
        <li><span>invoke方法通过反射执行了真实对象所属类(TrainStation)中的sell()方法</span></li>
    </ol>
    <h3><a name="515-cglib动态代理" class="md-header-anchor"></a><span>5.1.5 CGLIB动态代理</span></h3>
    <p><span>同样是上面的案例，我们再次使用CGLIB代理实现。</span></p>
    <p><span>如果没有定义SellTickets接口，只定义了TrainStation(火车站类)。很显然JDK代理是无法使用了，因为JDK动态代理要求必须定义接口，对接口进行代理。</span></p>
    <p><span>CGLIB是一个功能强大，高性能的代码生成包。它为没有实现接口的类提供代理，为JDK的动态代理提供了很好的补充。</span></p>
    <p><span>CGLIB是第三方提供的包，所以需要引入jar包的坐标：</span></p>
    <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="xml"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="xml"><div
            style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 36px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0"
                                                                                                                   style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div
            class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div
            class="CodeMirror-sizer" style="margin-left: 28px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div
            style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div
            class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>5</div></div></div><div
            class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline"
                                                                                                                                                               style="position: relative;"><div
            class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter"
                                                                                          style="left: -28px; width: 28px;"></div><div
            class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                     style="left: 0px; width: 19px;">1</div></div><pre class=" CodeMirror-line "
                                                                                                                                                       role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span class="cm-tag cm-bracket">&lt;</span><span class="cm-tag">dependency</span><span
            class="cm-tag cm-bracket">&gt;</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-tag cm-bracket">&lt;</span><span class="cm-tag">groupId</span><span class="cm-tag cm-bracket">&gt;</span>cglib<span class="cm-tag cm-bracket">&lt;/</span><span
            class="cm-tag">groupId</span><span class="cm-tag cm-bracket">&gt;</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                             style="left: -28px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-tag cm-bracket">&lt;</span><span class="cm-tag">artifactId</span><span class="cm-tag cm-bracket">&gt;</span>cglib<span class="cm-tag cm-bracket">&lt;/</span><span
            class="cm-tag">artifactId</span><span class="cm-tag cm-bracket">&gt;</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                style="left: -28px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-tag cm-bracket">&lt;</span><span class="cm-tag">version</span><span class="cm-tag cm-bracket">&gt;</span>2.2.2<span class="cm-tag cm-bracket">&lt;/</span><span
            class="cm-tag">version</span><span class="cm-tag cm-bracket">&gt;</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                             style="left: -28px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 19px;">5</div></div><pre class=" CodeMirror-line "
                                                                                                                                             role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            class="cm-tag cm-bracket">&lt;/</span><span class="cm-tag">dependency</span><span class="cm-tag cm-bracket">&gt;</span></span></pre></div></div></div></div></div></div><div
            style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 113px;"></div><div class="CodeMirror-gutters" style="height: 113px;"><div
            class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 27px;"></div></div></div></div></pre>
    <p><span>代码如下：</span></p>
    <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="java" style="break-inside: unset;"><div
            class="CodeMirror cm-s-inner CodeMirror-wrap" lang="java"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 44px;"><textarea
            autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0"
            style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler"
                                                                                                                                     cm-not-content="true"></div><div
            class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer"
                                                                                                                           style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div
            style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div
            class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>50</div></div></div><div
            class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline"
                                                                                                                                                               style="position: relative;"><div
            class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter"
                                                                                          style="left: -36px; width: 36px;"></div><div
            class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                     style="left: 0px; width: 27px;">1</div></div><pre class=" CodeMirror-line "
                                                                                                                                                       role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//火车站</span></span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
            class="cm-def">TrainStation</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"><span
            cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-variable-3">void</span> <span class="cm-variable">sell</span>() {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">5</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">System</span>.<span
            class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-string">"火车站卖票"</span>);</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">8</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                         style="left: 0px; width: 27px;">9</div></div><pre class=" CodeMirror-line "
                                                                                                                                                           role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//代理工厂</span></span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                        style="left: 0px; width: 27px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span class="cm-def">ProxyFactory</span> <span
            class="cm-keyword">implements</span> <span class="cm-variable">MethodInterceptor</span> {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">11</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">12</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">private</span> <span
            class="cm-variable">TrainStation</span> <span class="cm-variable">target</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">TrainStation</span>();</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">13</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">14</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable">TrainStation</span> <span class="cm-variable">getProxyObject</span>() {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">15</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-comment">//创建Enhancer对象，类似于JDK动态代理的Proxy类，下一步就是设置几个参数</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">16</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">Enhancer</span> <span
            class="cm-variable">enhancer</span> <span class="cm-operator">=</span><span class="cm-keyword">new</span> <span class="cm-variable">Enhancer</span>();</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">17</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">//设置父类的字节码对象</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">18</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">enhancer</span>.<span class="cm-variable">setSuperclass</span>(<span class="cm-variable">target</span>.<span
            class="cm-variable">getClass</span>());</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">19</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">//设置回调函数</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">20</div></div><pre class=" CodeMirror-line "
                                                                                                                                              role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">enhancer</span>.<span class="cm-variable">setCallback</span>(<span class="cm-keyword">this</span>);</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">21</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">//创建代理对象</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">22</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">TrainStation</span> <span class="cm-variable">obj</span> <span class="cm-operator">=</span> (<span class="cm-variable">TrainStation</span>) <span
            class="cm-variable">enhancer</span>.<span class="cm-variable">create</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                   style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">23</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-keyword">return</span> <span class="cm-variable">obj</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                           style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">24</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">25</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">26</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-comment">/*</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">27</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">intercept方法参数说明：</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">28</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">o ： 代理对象</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">29</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">method ： 真实对象中的方法的Method实例</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">30</div></div><pre class=" CodeMirror-line "
                                                                                                                                              role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">args ： 实际参数</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">31</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">methodProxy ：代理对象中的方法的method实例</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                        style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">32</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; <span
            class="cm-comment">*/</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">33</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-variable">TrainStation</span> <span class="cm-variable">intercept</span>(<span class="cm-variable-3">Object</span> <span
            class="cm-variable">o</span>, <span class="cm-variable">Method</span> <span class="cm-variable">method</span>, <span class="cm-variable-3">Object</span>[] <span
            class="cm-variable">args</span>, <span class="cm-variable">MethodProxy</span> <span class="cm-variable">methodProxy</span>) <span class="cm-keyword">throws</span> <span
            class="cm-variable">Throwable</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">34</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span
            class="cm-string">"代理点收取一些服务费用(CGLIB动态代理方式)"</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                           style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">35</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">TrainStation</span> <span class="cm-variable">result</span> <span class="cm-operator">=</span> (<span class="cm-variable">TrainStation</span>) <span
            class="cm-variable">methodProxy</span>.<span class="cm-variable">invokeSuper</span>(<span class="cm-variable">o</span>, <span class="cm-variable">args</span>);</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">36</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">return</span> <span
            class="cm-variable">result</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">37</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">38</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">39</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 27px;">40</div></div><pre class=" CodeMirror-line "
                                                                                                                                                            role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//测试类</span></span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">41</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
            class="cm-def">Client</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">42</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-keyword">static</span> <span class="cm-variable-3">void</span> <span class="cm-variable">main</span>(<span class="cm-variable-3">String</span>[] <span
            class="cm-variable">args</span>) {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">43</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">//创建代理工厂对象</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">44</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">ProxyFactory</span> <span class="cm-variable">factory</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">ProxyFactory</span>();</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">45</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">//获取代理对象</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">46</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">TrainStation</span> <span class="cm-variable">proxyObject</span> <span class="cm-operator">=</span> <span class="cm-variable">factory</span>.<span
            class="cm-variable">getProxyObject</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">47</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">48</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">proxyObject</span>.<span class="cm-variable">sell</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                    style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">49</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 27px;">50</div></div><pre class=" CodeMirror-line "
                                                                                                                                                            role="presentation"><span
            role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div
            style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 1156px;"></div><div class="CodeMirror-gutters" style="height: 1156px;"><div
            class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div></div></div></div></pre>
    <h3><a name="516-三种代理的对比" class="md-header-anchor"></a><span>5.1.6 三种代理的对比</span></h3>
    <ul>
        <li><p><span>jdk代理和CGLIB代理</span></p>
            <p>
                <span>使用CGLib实现动态代理，CGLib底层采用ASM字节码生成框架，使用字节码技术生成代理类，在JDK1.6之前比使用Java反射效率要高。唯一需要注意的是，CGLib不能对声明为final的类或者方法进行代理，因为CGLib原理是动态生成被代理类的子类。</span>
            </p>
            <p><span>在JDK1.6、JDK1.7、JDK1.8逐步对JDK动态代理优化之后，在调用次数较少的情况下，JDK代理效率高于CGLib代理效率，只有当进行大量调用的时候，JDK1.6和JDK1.7比CGLib代理效率低一点，但是到JDK1.8的时候，JDK代理效率高于CGLib代理。所以如果有接口使用JDK动态代理，如果没有接口使用CGLIB代理。</span>
            </p></li>
        <li><p><span>动态代理和静态代理</span></p>
            <p>
                <span>动态代理与静态代理相比较，最大的好处是接口中声明的所有方法都被转移到调用处理器一个集中的方法中处理（InvocationHandler.invoke）。这样，在接口方法数量比较多的时候，我们可以进行灵活处理，而不需要像静态代理那样每一个方法进行中转。</span>
            </p>
            <p><span>如果接口增加一个方法，静态代理模式除了所有实现类需要实现这个方法外，所有代理类也需要实现此方法。增加了代码维护的复杂度。而动态代理不会出现该问题</span></p></li>
    </ul>
    <p>&nbsp;</p>
    <h3><a name="517-优缺点" class="md-header-anchor"></a><span>5.1.7 优缺点</span></h3>
    <p><strong><span>优点：</span></strong></p>
    <ul>
        <li><span>代理模式在客户端与目标对象之间起到一个中介作用和保护目标对象的作用；</span></li>
        <li><span>代理对象可以扩展目标对象的功能；</span></li>
        <li><span>代理模式能将客户端与目标对象分离，在一定程度上降低了系统的耦合度；</span></li>
    </ul>
    <p><strong><span>缺点：</span></strong></p>
    <ul>
        <li><span>增加了系统的复杂度；</span></li>
    </ul>
    <p>&nbsp;</p>
    <h3><a name="518-使用场景" class="md-header-anchor"></a><span>5.1.8 使用场景 </span></h3>
    <ul>
        <li><p><span>远程（Remote）代理</span></p>
            <p>
                <span>本地服务通过网络请求远程服务。为了实现本地到远程的通信，我们需要实现网络通信，处理其中可能的异常。为良好的代码设计和可维护性，我们将网络通信部分隐藏起来，只暴露给本地服务一个接口，通过该接口即可访问远程服务提供的功能，而不必过多关心通信部分的细节。</span>
            </p></li>
        <li><p><span>防火墙（Firewall）代理</span></p>
            <p><span>当你将浏览器配置成使用代理功能时，防火墙就将你的浏览器的请求转给互联网；当互联网返回响应时，代理服务器再把它转给你的浏览器。</span></p></li>
        <li><p><span>保护（Protect or Access）代理</span></p>
            <p><span>控制对一个对象的访问，如果需要，可以给不同的用户提供不同级别的使用权限。</span></p></li>
    </ul>
    <p>&nbsp;</p>
    <h2><a name="52-适配器模式" class="md-header-anchor"></a><span>5.2 适配器模式</span></h2>
    <h3><a name="521-概述" class="md-header-anchor"></a><span>5.2.1 概述</span></h3>
    <p>
        <span>如果去欧洲国家去旅游的话，他们的插座如下图最左边，是欧洲标准。而我们使用的插头如下图最右边的。因此我们的笔记本电脑，手机在当地不能直接充电。所以就需要一个插座转换器，转换器第1面插入当地的插座，第2面供我们充电，这样使得我们的插头在当地能使用。生活中这样的例子很多，手机充电器（将220v转换为5v的电压），读卡器等，其实就是使用到了适配器模式。</span>
    </p>
    <p><img src="img\转接头.png" referrerpolicy="no-referrer"></p>
    <p><strong><span>定义：</span></strong></p>
    <p><span>	</span><span>将一个类的接口转换成客户希望的另外一个接口，使得原本由于接口不兼容而不能一起工作的那些类能一起工作。</span></p>
    <p><span>	</span><span>适配器模式分为类适配器模式和对象适配器模式，前者类之间的耦合度比后者高，且要求程序员了解现有组件库中的相关组件的内部结构，所以应用相对较少些。</span></p>
    <h3><a name="522-结构" class="md-header-anchor"></a><span>5.2.2 结构</span></h3>
    <p><span>适配器模式（Adapter）包含以下主要角色：</span></p>
    <ul>
        <li><span>目标（Target）接口：当前系统业务所期待的接口，它可以是抽象类或接口。</span></li>
        <li><span>适配者（Adaptee）类：它是被访问和适配的现存组件库中的组件接口。</span></li>
        <li><span>适配器（Adapter）类：它是一个转换器，通过继承或引用适配者的对象，把适配者接口转换成目标接口，让客户按目标接口的格式访问适配者。</span></li>
    </ul>
    <h3><a name="523-类适配器模式" class="md-header-anchor"></a><span>5.2.3 类适配器模式</span></h3>
    <p><span>实现方式：定义一个适配器类来实现当前系统的业务接口，同时又继承现有组件库中已经存在的组件。</span></p>
    <p><span>【例】读卡器</span></p>
    <p><span>现有一台电脑只能读取SD卡，而要读取TF卡中的内容的话就需要使用到适配器模式。创建一个读卡器，将TF卡中的内容读取出来。</span></p>
    <p><span>类图如下：</span></p>
    <p><img src="img/适配器模式.png" style="zoom:80%;"/></p>
    <p><span>代码如下：</span></p>
    <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="java" style="break-inside: unset;"><div
            class="CodeMirror cm-s-inner CodeMirror-wrap" lang="java"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 44px;"><textarea
            autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0"
            style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler"
                                                                                                                                     cm-not-content="true"></div><div
            class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer"
                                                                                                                           style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div
            style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div
            class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>79</div></div></div><div
            class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline"
                                                                                                                                                               style="position: relative;"><div
            class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter"
                                                                                          style="left: -36px; width: 36px;"></div><div
            class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                     style="left: 0px; width: 27px;">1</div></div><pre class=" CodeMirror-line "
                                                                                                                                                       role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//SD卡的接口</span></span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span
            class="cm-keyword">interface</span> <span class="cm-def">SDCard</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                             style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-comment">//读取SD卡方法</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-variable-3">String</span> <span class="cm-variable">readSD</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                   style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-comment">//写入SD卡功能</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-variable-3">void</span> <span class="cm-variable">writeSD</span>(<span class="cm-variable-3">String</span> <span class="cm-variable">msg</span>);</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                         style="left: 0px; width: 27px;">7</div></div><pre class=" CodeMirror-line "
                                                                                                                                                           role="presentation"><span
            role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"><span
            cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"><span
            class="cm-comment">//SD卡实现类</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">10</div></div><pre class=" CodeMirror-line "
                                                                                                                                              role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"><span
            class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span class="cm-def">SDCardImpl</span> <span class="cm-keyword">implements</span> <span
            class="cm-variable">SDCard</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-variable-3">String</span> <span class="cm-variable">readSD</span>() {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">12</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable-3">String</span> <span
            class="cm-variable">msg</span> <span class="cm-operator">=</span> <span class="cm-string">"sd card read a msg :hello word SD"</span>;</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">13</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">return</span> <span
            class="cm-variable">msg</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">15</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">16</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable-3">void</span> <span class="cm-variable">writeSD</span>(<span class="cm-variable-3">String</span> <span class="cm-variable">msg</span>) {</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">17</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">System</span>.<span
            class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-string">"sd card write msg : "</span> <span class="cm-operator">+</span> <span
            class="cm-variable">msg</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">18</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">19</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                        style="left: 0px; width: 27px;">20</div></div><pre class=" CodeMirror-line " role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">21</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            class="cm-comment">//电脑类</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">22</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span class="cm-def">Computer</span> {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">23</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">24</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable-3">String</span> <span class="cm-variable">readSD</span>(<span class="cm-variable">SDCard</span> <span class="cm-variable">sdCard</span>) {</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">25</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">if</span>(<span
            class="cm-variable">sdCard</span> <span class="cm-operator">==</span> <span class="cm-atom">null</span>) {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">26</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-keyword">throw</span> <span class="cm-keyword">new</span> <span class="cm-variable">NullPointerException</span>(<span
            class="cm-string">"sd card null"</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">27</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">28</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">return</span> <span
            class="cm-variable">sdCard</span>.<span class="cm-variable">readSD</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                 style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">29</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 27px;">30</div></div><pre class=" CodeMirror-line "
                                                                                                                                                            role="presentation"><span
            role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">31</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">32</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            class="cm-comment">//TF卡接口</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">33</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            class="cm-keyword">public</span> <span class="cm-keyword">interface</span> <span class="cm-def">TFCard</span> {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">34</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-comment">//读取TF卡方法</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">35</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-variable-3">String</span> <span class="cm-variable">readTF</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                   style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">36</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-comment">//写入TF卡功能</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">37</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-variable-3">void</span> <span class="cm-variable">writeTF</span>(<span class="cm-variable-3">String</span> <span class="cm-variable">msg</span>);</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">38</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">39</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 27px;">40</div></div><pre class=" CodeMirror-line "
                                                                                                                                                            role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//TF卡实现类</span></span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">41</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
            class="cm-def">TFCardImpl</span> <span class="cm-keyword">implements</span> <span class="cm-variable">TFCard</span> {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">42</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">43</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable-3">String</span> <span class="cm-variable">readTF</span>() {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                    style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">44</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable-3">String</span> <span class="cm-variable">msg</span> <span class="cm-operator">=</span><span class="cm-string">"tf card read msg : hello word tf card"</span>;</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">45</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">return</span> <span
            class="cm-variable">msg</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">46</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">47</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">48</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable-3">void</span> <span class="cm-variable">writeTF</span>(<span class="cm-variable-3">String</span> <span class="cm-variable">msg</span>) {</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">49</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">System</span>.<span
            class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-string">"tf card write a msg : "</span> <span class="cm-operator">+</span> <span
            class="cm-variable">msg</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">50</div></div><pre class=" CodeMirror-line "
                                                                                                                                              role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">51</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">52</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">53</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//定义适配器类（SD兼容TF）</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">54</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
            class="cm-def">SDAdapterTF</span> <span class="cm-keyword">extends</span> <span class="cm-variable">TFCardImpl</span> <span class="cm-keyword">implements</span> <span
            class="cm-variable">SDCard</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">55</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">56</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-variable-3">String</span> <span class="cm-variable">readSD</span>() {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">57</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">System</span>.<span
            class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-string">"adapter read tf card "</span>);</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">58</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">return</span> <span
            class="cm-variable">readTF</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">59</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 27px;">60</div></div><pre class=" CodeMirror-line "
                                                                                                                                                            role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">61</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-variable-3">void</span> <span class="cm-variable">writeSD</span>(<span class="cm-variable-3">String</span> <span
            class="cm-variable">msg</span>) {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">62</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span
            class="cm-string">"adapter write tf card"</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">63</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">writeTF</span>(<span class="cm-variable">msg</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                              style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">64</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">65</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">66</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">67</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//测试类</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">68</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
            class="cm-def">Client</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">69</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-keyword">static</span> <span class="cm-variable-3">void</span> <span class="cm-variable">main</span>(<span class="cm-variable-3">String</span>[] <span
            class="cm-variable">args</span>) {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">70</div></div><pre class=" CodeMirror-line "
                                                                                                                                              role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">Computer</span> <span class="cm-variable">computer</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">Computer</span>();</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">71</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">SDCard</span> <span
            class="cm-variable">sdCard</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">SDCardImpl</span>();</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">72</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">System</span>.<span
            class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-variable">computer</span>.<span class="cm-variable">readSD</span>(<span
            class="cm-variable">sdCard</span>));</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">73</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">74</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-string">"------------"</span>);</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">75</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">76</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">SDAdapterTF</span> <span class="cm-variable">adapter</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">SDAdapterTF</span>();</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">77</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">System</span>.<span
            class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-variable">computer</span>.<span class="cm-variable">readSD</span>(<span
            class="cm-variable">adapter</span>));</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">78</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 27px;">79</div></div><pre class=" CodeMirror-line "
                                                                                                                                                            role="presentation"><span
            role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div
            style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 1791px;"></div><div class="CodeMirror-gutters" style="height: 1791px;"><div
            class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div></div></div></div></pre>
    <p><span>类适配器模式违背了合成复用原则。类适配器是客户类有一个接口规范的情况下可用，反之不可用。</span></p>
    <p>&nbsp;</p>
    <h3><a name="524-对象适配器模式" class="md-header-anchor"></a><span>5.2.4 对象适配器模式</span></h3>
    <p><span>实现方式：对象适配器模式可釆用将现有组件库中已经实现的组件引入适配器类中，该类同时实现当前系统的业务接口。</span></p>
    <p><span>【例】读卡器</span></p>
    <p><span>我们使用对象适配器模式将读卡器的案例进行改写。类图如下：</span></p>
    <p><img src="img\对象适配器模式.png" style="zoom:80%;"/></p>
    <p><span>代码如下：</span></p>
    <p><span>类适配器模式的代码，我们只需要修改适配器类（SDAdapterTF）和测试类。</span></p>
    <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="java" style="break-inside: unset;"><div
            class="CodeMirror cm-s-inner CodeMirror-wrap" lang="java"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 44px;"><textarea
            autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0"
            style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler"
                                                                                                                                     cm-not-content="true"></div><div
            class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer"
                                                                                                                           style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div
            style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div
            class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>34</div></div></div><div
            class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline"
                                                                                                                                                               style="position: relative;"><div
            class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter"
                                                                                          style="left: -36px; width: 36px;"></div><div
            class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                     style="left: 0px; width: 27px;">1</div></div><pre class=" CodeMirror-line "
                                                                                                                                                       role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//创建适配器对象（SD兼容TF）</span></span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
            class="cm-def">SDAdapterTF</span> &nbsp;<span class="cm-keyword">implements</span> <span class="cm-variable">SDCard</span> {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                         style="left: 0px; width: 27px;">4</div></div><pre class=" CodeMirror-line "
                                                                                                                                                           role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">private</span> <span class="cm-variable">TFCard</span> <span
            class="cm-variable">tfCard</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"><span
            cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-variable">SDAdapterTF</span>(<span class="cm-variable">TFCard</span> <span
            class="cm-variable">tfCard</span>) {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-keyword">this</span>.<span class="cm-variable">tfCard</span> <span class="cm-operator">=</span> <span class="cm-variable">tfCard</span>;</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                         style="left: 0px; width: 27px;">8</div></div><pre class=" CodeMirror-line "
                                                                                                                                                           role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"><span
            cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">10</div></div><pre class=" CodeMirror-line "
                                                                                                                                              role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-variable-3">String</span> <span class="cm-variable">readSD</span>() {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">11</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">System</span>.<span
            class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-string">"adapter read tf card "</span>);</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">12</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">return</span> <span
            class="cm-variable">tfCard</span>.<span class="cm-variable">readTF</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                 style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">14</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">15</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable-3">void</span> <span class="cm-variable">writeSD</span>(<span class="cm-variable-3">String</span> <span class="cm-variable">msg</span>) {</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">16</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">System</span>.<span
            class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-string">"adapter write tf card"</span>);</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">17</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">tfCard</span>.<span
            class="cm-variable">writeTF</span>(<span class="cm-variable">msg</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                              style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">18</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">19</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                        style="left: 0px; width: 27px;">20</div></div><pre class=" CodeMirror-line " role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">21</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            class="cm-comment">//测试类</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">22</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span class="cm-def">Client</span> {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">23</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-keyword">static</span> <span class="cm-variable-3">void</span> <span class="cm-variable">main</span>(<span class="cm-variable-3">String</span>[] <span
            class="cm-variable">args</span>) {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">24</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">Computer</span> <span class="cm-variable">computer</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">Computer</span>();</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">25</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">SDCard</span> <span
            class="cm-variable">sdCard</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">SDCardImpl</span>();</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">26</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">System</span>.<span
            class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-variable">computer</span>.<span class="cm-variable">readSD</span>(<span
            class="cm-variable">sdCard</span>));</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">27</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">28</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-string">"------------"</span>);</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">29</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 27px;">30</div></div><pre class=" CodeMirror-line "
                                                                                                                                                            role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">TFCard</span> <span class="cm-variable">tfCard</span> <span
            class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">TFCardImpl</span>();</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">31</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">SDAdapterTF</span> <span class="cm-variable">adapter</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">SDAdapterTF</span>(<span
            class="cm-variable">tfCard</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">32</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-variable">computer</span>.<span
            class="cm-variable">readSD</span>(<span class="cm-variable">adapter</span>));</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                  style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">33</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 27px;">34</div></div><pre class=" CodeMirror-line "
                                                                                                                                                            role="presentation"><span
            role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div
            style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 771px;"></div><div class="CodeMirror-gutters" style="height: 771px;"><div
            class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div></div></div></div></pre>
    <blockquote><p><span>注意：还有一个适配器模式是接口适配器模式。当不希望实现一个接口中所有的方法时，可以创建一个抽象类Adapter ，实现所有方法。而此时我们只需要继承该抽象类即可。</span></p>
    </blockquote>
    <p>&nbsp;</p>
    <h3><a name="525-应用场景" class="md-header-anchor"></a><span>5.2.5 应用场景</span></h3>
    <ul>
        <li><span>以前开发的系统存在满足新系统功能需求的类，但其接口同新系统的接口不一致。</span></li>
        <li><span>使用第三方提供的组件，但组件接口定义和自己要求的接口定义不同。</span></li>
    </ul>
    <p>&nbsp;</p>
    <h3><a name="526-jdk源码解析" class="md-header-anchor"></a><span>5.2.6 JDK源码解析</span></h3>
    <p><span>Reader（字符流）、InputStream（字节流）的适配使用的是InputStreamReader。</span></p>
    <p><span>InputStreamReader继承自java.io包中的Reader，对他中的抽象的未实现的方法给出实现。如：</span></p>
    <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="java"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="java"><div
            style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 36px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0"
                                                                                                                   style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div
            class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div
            class="CodeMirror-sizer" style="margin-left: 28px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div
            style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div
            class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>7</div></div></div><div
            class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline"
                                                                                                                                                               style="position: relative;"><div
            class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter"
                                                                                          style="left: -28px; width: 28px;"></div><div
            class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                     style="left: 0px; width: 19px;">1</div></div><pre class=" CodeMirror-line "
                                                                                                                                                       role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-variable-3">int</span> <span class="cm-def">read</span>() <span
            class="cm-keyword">throws</span> <span class="cm-variable">IOException</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                    style="left: -28px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">return</span> <span class="cm-variable">sd</span>.<span class="cm-variable">read</span>();</span></pre></div><div style="position: relative;" class=""><div
            class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">3</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">4</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                         style="left: 0px; width: 19px;">5</div></div><pre class=" CodeMirror-line "
                                                                                                                                                           role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-variable-3">int</span> <span class="cm-def">read</span>(<span
            class="cm-variable-3">char</span> <span class="cm-variable">cbuf</span>[], <span class="cm-variable-3">int</span> <span class="cm-variable">offset</span>, <span
            class="cm-variable-3">int</span> <span class="cm-variable">length</span>) <span class="cm-keyword">throws</span> <span class="cm-variable">IOException</span> {</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                         style="left: 0px; width: 19px;">6</div></div><pre class=" CodeMirror-line "
                                                                                                                                                           role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">return</span> <span class="cm-variable">sd</span>.<span
            class="cm-variable">read</span>(<span class="cm-variable">cbuf</span>, <span class="cm-variable">offset</span>, <span class="cm-variable">length</span>);</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -28px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 19px;">7</div></div><pre class=" CodeMirror-line "
                                                                                                                                                           role="presentation"><span
            role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div
            style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 159px;"></div><div class="CodeMirror-gutters" style="height: 159px;"><div
            class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 27px;"></div></div></div></div></pre>
    <p><span>如上代码中的sd（StreamDecoder类对象），在Sun的JDK实现中，实际的方法实现是对sun.nio.cs.StreamDecoder类的同名方法的调用封装。类结构图如下：</span></p>
    <p><img src="img\适配器模式-jdk源码解析.png" referrerpolicy="no-referrer"></p>
    <p><span>从上图可以看出：</span></p>
    <ul>
        <li><span>InputStreamReader是对同样实现了Reader的StreamDecoder的封装。</span></li>
        <li><span>StreamDecoder不是Java SE API中的内容，是Sun  JDK给出的自身实现。但我们知道他们对构造方法中的字节流类（InputStream）进行封装，并通过该类进行了字节流和字符流之间的解码转换。</span>
        </li>
    </ul>
    <p><font color="red"><span>结论：</span></font></p>
    <p>
        <span>	</span><span>从表层来看，InputStreamReader做了InputStream字节流类到Reader字符流之间的转换。而从如上Sun JDK中的实现类关系结构中可以看出，是StreamDecoder的设计实现在实际上采用了适配器模式。</span>
    </p>
    <p>&nbsp;</p>
    <h2><a name="53-装饰者模式" class="md-header-anchor"></a><span>5.3 装饰者模式</span></h2>
    <h3><a name="531-概述" class="md-header-anchor"></a><span>5.3.1 概述</span></h3>
    <p><span>我们先来看一个快餐店的例子。</span></p>
    <p><span>快餐店有炒面、炒饭这些快餐，可以额外附加鸡蛋、火腿、培根这些配菜，当然加配菜需要额外加钱，每个配菜的价钱通常不太一样，那么计算总价就会显得比较麻烦。</span></p>
    <p><img src="D:/传智播客/专题/设计模式/成品/笔记/assets/装饰者模式-使用前.png" style="zoom:80%;"/></p>
    <p><span>使用继承的方式存在的问题：</span></p>
    <ul>
        <li><p><span>扩展性不好</span></p>
            <p><span>如果要再加一种配料（火腿肠），我们就会发现需要给FriedRice和FriedNoodles分别定义一个子类。如果要新增一个快餐品类（炒河粉）的话，就需要定义更多的子类。</span></p></li>
        <li><p><span>产生过多的子类</span></p></li>
    </ul>
    <p><strong><span>定义：</span></strong></p>
    <p><span>	</span><span>指在不改变现有对象结构的情况下，动态地给该对象增加一些职责（即增加其额外功能）的模式。</span></p>
    <h3><a name="532-结构" class="md-header-anchor"></a><span>5.3.2 结构</span></h3>
    <p><span>装饰（Decorator）模式中的角色：</span></p>
    <ul>
        <li><span>抽象构件（Component）角色 ：定义一个抽象接口以规范准备接收附加责任的对象。</span></li>
        <li><span>具体构件（Concrete  Component）角色 ：实现抽象构件，通过装饰角色为其添加一些职责。</span></li>
        <li><span>抽象装饰（Decorator）角色 ： 继承或实现抽象构件，并包含具体构件的实例，可以通过其子类扩展具体构件的功能。</span></li>
        <li><span>具体装饰（ConcreteDecorator）角色 ：实现抽象装饰的相关方法，并给具体构件对象添加附加的责任。</span></li>
    </ul>
    <p>&nbsp;</p>
    <h3><a name="533-案例" class="md-header-anchor"></a><span>5.3.3 案例</span></h3>
    <p><span>我们使用装饰者模式对快餐店案例进行改进，体会装饰者模式的精髓。</span></p>
    <p><span>类图如下：</span></p>
    <p><img src="img/装饰者模式.png" style="zoom:75%;"/></p>
    <p><span>代码如下：</span></p>
    <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="java" style="break-inside: unset;"><div
            class="CodeMirror cm-s-inner CodeMirror-wrap" lang="java"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 53px;"><textarea
            autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0"
            style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler"
                                                                                                                                     cm-not-content="true"></div><div
            class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer"
                                                                                                                           style="margin-left: 45px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div
            style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div
            class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>135</div></div></div><div
            class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline"
                                                                                                                                                               style="position: relative;"><div
            class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter"
                                                                                          style="left: -45px; width: 45px;"></div><div
            class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                     style="left: 0px; width: 36px;">1</div></div><pre class=" CodeMirror-line "
                                                                                                                                                       role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//快餐接口</span></span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">2</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span
            class="cm-keyword">abstract</span> <span class="cm-keyword">class</span> <span class="cm-def">FastFood</span> {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">3</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">private</span> <span
            class="cm-keyword">float</span> <span class="cm-variable">price</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                            style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">private</span> <span class="cm-variable-3">String</span> <span class="cm-variable">desc</span>;</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">5</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                         style="left: 0px; width: 36px;">6</div></div><pre class=" CodeMirror-line "
                                                                                                                                                           role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span class="cm-variable">FastFood</span>() {</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                         style="left: 0px; width: 36px;">7</div></div><pre class=" CodeMirror-line "
                                                                                                                                                           role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"><span
            cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-variable">FastFood</span>(<span class="cm-keyword">float</span> <span class="cm-variable">price</span>, <span
            class="cm-variable-3">String</span> <span class="cm-variable">desc</span>) {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                 style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">10</div></div><pre class=" CodeMirror-line "
                                                                                                                                              role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-keyword">this</span>.<span class="cm-variable">price</span> <span class="cm-operator">=</span> <span class="cm-variable">price</span>;</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">11</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">this</span>.<span
            class="cm-variable">desc</span> <span class="cm-operator">=</span> <span class="cm-variable">desc</span>;</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">12</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">13</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">14</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable-3">void</span> <span class="cm-variable">setPrice</span>(<span class="cm-keyword">float</span> <span class="cm-variable">price</span>) {</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">15</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">this</span>.<span
            class="cm-variable">price</span> <span class="cm-operator">=</span> <span class="cm-variable">price</span>;</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">16</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">17</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">18</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-keyword">float</span> <span class="cm-variable">getPrice</span>() {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                  style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">19</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-keyword">return</span> <span class="cm-variable">price</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                             style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">20</div></div><pre class=" CodeMirror-line "
                                                                                                                                              role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">21</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">22</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable-3">String</span> <span class="cm-variable">getDesc</span>() {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                     style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">23</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-keyword">return</span> <span class="cm-variable">desc</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                            style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">24</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">25</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">26</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable-3">void</span> <span class="cm-variable">setDesc</span>(<span class="cm-variable-3">String</span> <span class="cm-variable">desc</span>) {</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">27</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">this</span>.<span
            class="cm-variable">desc</span> <span class="cm-operator">=</span> <span class="cm-variable">desc</span>;</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">28</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">29</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 36px;">30</div></div><pre class=" CodeMirror-line "
                                                                                                                                                            role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span class="cm-keyword">abstract</span> <span
            class="cm-keyword">float</span> <span class="cm-variable">cost</span>(); &nbsp;<span class="cm-comment">//获取价格</span></span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">31</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">32</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">33</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//炒饭</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">34</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
            class="cm-def">FriedRice</span> <span class="cm-keyword">extends</span> <span class="cm-variable">FastFood</span> {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">35</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">36</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable">FriedRice</span>() {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">37</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-keyword">super</span>(<span class="cm-number">10</span>, <span class="cm-string">"炒饭"</span>);</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">38</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">39</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 36px;">40</div></div><pre class=" CodeMirror-line "
                                                                                                                                                            role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span class="cm-keyword">float</span> <span class="cm-variable">cost</span>() {</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">41</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">return</span> <span
            class="cm-variable">getPrice</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">42</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">43</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">44</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">45</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//炒面</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">46</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
            class="cm-def">FriedNoodles</span> <span class="cm-keyword">extends</span> <span class="cm-variable">FastFood</span> {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">47</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">48</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable">FriedNoodles</span>() {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">49</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-keyword">super</span>(<span class="cm-number">12</span>, <span class="cm-string">"炒面"</span>);</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                        style="left: 0px; width: 36px;">50</div></div><pre class=" CodeMirror-line " role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">51</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">52</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-keyword">float</span> <span class="cm-variable">cost</span>() {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">53</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">return</span> <span
            class="cm-variable">getPrice</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">54</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">55</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">56</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">57</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//配料类</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">58</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span
            class="cm-keyword">abstract</span> <span class="cm-keyword">class</span> <span class="cm-def">Garnish</span> <span class="cm-keyword">extends</span> <span class="cm-variable">FastFood</span> {</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">59</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 36px;">60</div></div><pre class=" CodeMirror-line "
                                                                                                                                                            role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">private</span> <span class="cm-variable">FastFood</span> <span class="cm-variable">fastFood</span>;</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">61</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">62</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable">FastFood</span> <span class="cm-variable">getFastFood</span>() {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                         style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">63</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-keyword">return</span> <span class="cm-variable">fastFood</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">64</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">65</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">66</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable-3">void</span> <span class="cm-variable">setFastFood</span>(<span class="cm-variable">FastFood</span> <span class="cm-variable">fastFood</span>) {</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">67</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">this</span>.<span
            class="cm-variable">fastFood</span> <span class="cm-operator">=</span> <span class="cm-variable">fastFood</span>;</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">68</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">69</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 36px;">70</div></div><pre class=" CodeMirror-line "
                                                                                                                                                            role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span class="cm-variable">Garnish</span>(<span
            class="cm-variable">FastFood</span> <span class="cm-variable">fastFood</span>, <span class="cm-keyword">float</span> <span class="cm-variable">price</span>, <span
            class="cm-variable-3">String</span> <span class="cm-variable">desc</span>) {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                 style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">71</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-keyword">super</span>(<span class="cm-variable">price</span>,<span class="cm-variable">desc</span>);</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">72</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">this</span>.<span
            class="cm-variable">fastFood</span> <span class="cm-operator">=</span> <span class="cm-variable">fastFood</span>;</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">73</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">74</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">75</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">76</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//鸡蛋配料</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">77</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
            class="cm-def">Egg</span> <span class="cm-keyword">extends</span> <span class="cm-variable">Garnish</span> {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">78</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">79</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable">Egg</span>(<span class="cm-variable">FastFood</span> <span class="cm-variable">fastFood</span>) {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                        style="left: 0px; width: 36px;">80</div></div><pre class=" CodeMirror-line " role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">super</span>(<span class="cm-variable">fastFood</span>,<span
            class="cm-number">1</span>,<span class="cm-string">"鸡蛋"</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">81</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">82</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">83</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-keyword">float</span> <span class="cm-variable">cost</span>() {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                              style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">84</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-keyword">return</span> <span class="cm-variable">getPrice</span>() <span class="cm-operator">+</span> <span class="cm-variable">getFastFood</span>().<span
            class="cm-variable">getPrice</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">85</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">86</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">87</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-meta">@Override</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">88</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable-3">String</span> <span class="cm-variable">getDesc</span>() {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                     style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">89</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-keyword">return</span> <span class="cm-keyword">super</span>.<span class="cm-variable">getDesc</span>() <span class="cm-operator">+</span> <span class="cm-variable">getFastFood</span>().<span
            class="cm-variable">getDesc</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">90</div></div><pre class=" CodeMirror-line "
                                                                                                                                              role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">91</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">92</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">93</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//培根配料</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">94</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
            class="cm-def">Bacon</span> <span class="cm-keyword">extends</span> <span class="cm-variable">Garnish</span> {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">95</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">96</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable">Bacon</span>(<span class="cm-variable">FastFood</span> <span class="cm-variable">fastFood</span>) {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">97</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">98</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">super</span>(<span
            class="cm-variable">fastFood</span>,<span class="cm-number">2</span>,<span class="cm-string">"培根"</span>);</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">99</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                        style="left: 0px; width: 36px;">100</div></div><pre class=" CodeMirror-line " role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">101</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-meta">@Override</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">102</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-keyword">float</span> <span class="cm-variable">cost</span>() {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">103</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">return</span> <span
            class="cm-variable">getPrice</span>() <span class="cm-operator">+</span> <span class="cm-variable">getFastFood</span>().<span class="cm-variable">getPrice</span>();</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">104</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">105</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">106</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-meta">@Override</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">107</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable-3">String</span> <span class="cm-variable">getDesc</span>() {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                     style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">108</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-keyword">return</span> <span class="cm-keyword">super</span>.<span class="cm-variable">getDesc</span>() <span class="cm-operator">+</span> <span class="cm-variable">getFastFood</span>().<span
            class="cm-variable">getDesc</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">109</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 36px;">110</div></div><pre class=" CodeMirror-line "
                                                                                                                                                             role="presentation"><span
            role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">111</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"><span
            cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">112</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"><span
            class="cm-comment">//测试类</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">113</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"><span
            class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span class="cm-def">Client</span> {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">114</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-keyword">static</span> <span class="cm-variable-3">void</span> <span class="cm-variable">main</span>(<span class="cm-variable-3">String</span>[] <span
            class="cm-variable">args</span>) {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">115</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">//点一份炒饭</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">116</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">FastFood</span> <span class="cm-variable">food</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">FriedRice</span>();</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">117</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">//花费的价格</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">118</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-variable">food</span>.<span class="cm-variable">getDesc</span>() <span
            class="cm-operator">+</span> <span class="cm-string">" "</span> <span class="cm-operator">+</span> <span class="cm-variable">food</span>.<span
            class="cm-variable">cost</span>() <span class="cm-operator">+</span> <span class="cm-string">"元"</span>);</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">119</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 36px;">120</div></div><pre class=" CodeMirror-line "
                                                                                                                                                             role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span
            class="cm-variable">println</span>(<span class="cm-string">"========"</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                   style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">121</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">//点一份加鸡蛋的炒饭</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">122</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">FastFood</span> <span class="cm-variable">food1</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">FriedRice</span>();</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">123</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">124</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">food1</span> <span
            class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">Egg</span>(<span class="cm-variable">food1</span>);</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">125</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">//花费的价格</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">126</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-variable">food1</span>.<span class="cm-variable">getDesc</span>() <span
            class="cm-operator">+</span> <span class="cm-string">" "</span> <span class="cm-operator">+</span> <span class="cm-variable">food1</span>.<span class="cm-variable">cost</span>() <span
            class="cm-operator">+</span> <span class="cm-string">"元"</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">127</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"><span
            cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">128</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-string">"========"</span>);</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">129</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">//点一份加培根的炒面</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 36px;">130</div></div><pre class=" CodeMirror-line "
                                                                                                                                               role="presentation"><span role="presentation"
                                                                                                                                                                         style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">FastFood</span> <span class="cm-variable">food2</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">FriedNoodles</span>();</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">131</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">food2</span> <span
            class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">Bacon</span>(<span class="cm-variable">food2</span>);</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">132</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">//花费的价格</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">133</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-variable">food2</span>.<span class="cm-variable">getDesc</span>() <span
            class="cm-operator">+</span> <span class="cm-string">" "</span> <span class="cm-operator">+</span> <span class="cm-variable">food2</span>.<span class="cm-variable">cost</span>() <span
            class="cm-operator">+</span> <span class="cm-string">"元"</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 36px;">134</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -45px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 36px;">135</div></div><pre class=" CodeMirror-line "
                                                                                                                                                             role="presentation"><span
            role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div
            style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 3060px;"></div><div class="CodeMirror-gutters" style="height: 3060px;"><div
            class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 44px;"></div></div></div></div></pre>
    <p><strong><span>好处：</span></strong></p>
    <ul>
        <li>
            <span>饰者模式可以带来比继承更加灵活性的扩展功能，使用更加方便，可以通过组合不同的装饰者对象来获取具有不同行为状态的多样化的结果。装饰者模式比继承更具良好的扩展性，完美的遵循开闭原则，继承是静态的附加责任，装饰者则是动态的附加责任。</span>
        </li>
        <li><span>装饰类和被装饰类可以独立发展，不会相互耦合，装饰模式是继承的一个替代模式，装饰模式可以动态扩展一个实现类的功能。</span></li>
    </ul>
    <p>&nbsp;</p>
    <h3><a name="534-使用场景" class="md-header-anchor"></a><span>5.3.4 使用场景</span></h3>
    <ul>
        <li><p><span>当不能采用继承的方式对系统进行扩充或者采用继承不利于系统扩展和维护时。</span></p>
            <p><span>不能采用继承的情况主要有两类：</span></p>
            <ul>
                <li><span>第一类是系统中存在大量独立的扩展，为支持每一种组合将产生大量的子类，使得子类数目呈爆炸性增长；</span></li>
                <li><span>第二类是因为类定义不能继承（如final类）</span></li>
            </ul>
        </li>
        <li><p><span>在不影响其他对象的情况下，以动态、透明的方式给单个对象添加职责。</span></p></li>
        <li><p><span>当对象的功能要求可以动态地添加，也可以再动态地撤销时。</span></p></li>
    </ul>
    <p>&nbsp;</p>
    <h3><a name="535-jdk源码解析" class="md-header-anchor"></a><span>5.3.5 JDK源码解析</span></h3>
    <p><span>IO流中的包装类使用到了装饰者模式。BufferedInputStream，BufferedOutputStream，BufferedReader，BufferedWriter。</span></p>
    <p><span>我们以BufferedWriter举例来说明，先看看如何使用BufferedWriter</span></p>
    <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="java"><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang="java"><div
            style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 44px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0"
                                                                                                                   style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div
            class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div
            class="CodeMirror-sizer" style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div
            style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div
            class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>13</div></div></div><div
            class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline"
                                                                                                                                                               style="position: relative;"><div
            class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter"
                                                                                          style="left: -36px; width: 36px;"></div><div
            class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                     style="left: 0px; width: 27px;">1</div></div><pre class=" CodeMirror-line "
                                                                                                                                                       role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
            class="cm-def">Demo</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-keyword">static</span> <span class="cm-variable-3">void</span> <span class="cm-variable">main</span>(<span class="cm-variable-3">String</span>[] <span
            class="cm-variable">args</span>) <span class="cm-keyword">throws</span> <span class="cm-variable">Exception</span>{</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">//创建BufferedWriter对象</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">//创建FileWriter对象</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">FileWriter</span> <span class="cm-variable">fw</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">FileWriter</span>(<span
            class="cm-string">"C:\\Users\\Think\\Desktop\\a.txt"</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">BufferedWriter</span> <span class="cm-variable">bw</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">BufferedWriter</span>(<span
            class="cm-variable">fw</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"><span
            cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">//写数据</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">bw</span>.<span class="cm-variable">write</span>(<span class="cm-string">"hello Buffered"</span>);</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                        style="left: 0px; width: 27px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">bw</span>.<span class="cm-variable">close</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                            style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 27px;">13</div></div><pre class=" CodeMirror-line "
                                                                                                                                                            role="presentation"><span
            role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div
            style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 295px;"></div><div class="CodeMirror-gutters" style="height: 295px;"><div
            class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div></div></div></div></pre>
    <p><span>使用起来感觉确实像是装饰者模式，接下来看它们的结构：</span></p>
    <p><img src="img\装饰者模式-jdk源码.png" style="zoom:80%;"/></p>
    <blockquote><p><font color="red"><span>小结：</span></font></p>
        <p><span>	</span><span>BufferedWriter使用装饰者模式对Writer子实现类进行了增强，添加了缓冲区，提高了写数据的效率。</span></p></blockquote>
    <p>&nbsp;</p>
    <h3><a name="536-代理和装饰者的区别" class="md-header-anchor"></a><span>5.3.6 代理和装饰者的区别</span></h3>
    <p><span>静态代理和装饰者模式的区别：</span></p>
    <ul>
        <li><p><span>相同点：</span></p>
            <ul>
                <li><span>都要实现与目标类相同的业务接口</span></li>
                <li><span>在两个类中都要声明目标对象</span></li>
                <li><span>都可以在不修改目标类的前提下增强目标方法</span></li>
            </ul>
        </li>
        <li><p><span>不同点：</span></p>
            <ul>
                <li><span>目的不同</span>
                    <span>装饰者是为了增强目标对象</span>
                    <span>静态代理是为了保护和隐藏目标对象</span></li>
                <li><span>获取目标对象构建的地方不同</span>
                    <span>装饰者是由外界传递进来，可以通过构造方法传递</span>
                    <span>静态代理是在代理类内部创建，以此来隐藏目标对象</span></li>
            </ul>
        </li>
    </ul>
    <p>&nbsp;</p>
    <h2><a name="54-桥接模式" class="md-header-anchor"></a><span>5.4 桥接模式</span></h2>
    <h3><a name="541-概述" class="md-header-anchor"></a><span>5.4.1 概述</span></h3>
    <p><span>现在有一个需求，需要创建不同的图形，并且每个图形都有可能会有不同的颜色。我们可以利用继承的方式来设计类的关系：</span></p>
    <p><img src="img\image-20200207194617620.png" referrerpolicy="no-referrer"></p>
    <p><span>我们可以发现有很多的类，假如我们再增加一个形状或再增加一种颜色，就需要创建更多的类。</span></p>
    <p>
        <span>试想，在一个有多种可能会变化的维度的系统中，用继承方式会造成类爆炸，扩展起来不灵活。每次在一个维度上新增一个具体实现都要增加多个子类。为了更加灵活的设计系统，我们此时可以考虑使用桥接模式。</span>
    </p>
    <p><strong><span>定义：</span></strong></p>
    <p><span>	</span><span>将抽象与实现分离，使它们可以独立变化。它是用组合关系代替继承关系来实现，从而降低了抽象和实现这两个可变维度的耦合度。</span></p>
    <p>&nbsp;</p>
    <h3><a name="542-结构" class="md-header-anchor"></a><span>5.4.2 结构</span></h3>
    <p><span>桥接（Bridge）模式包含以下主要角色：</span></p>
    <ul>
        <li><span>抽象化（Abstraction）角色 ：定义抽象类，并包含一个对实现化对象的引用。</span></li>
        <li><span>扩展抽象化（Refined  Abstraction）角色 ：是抽象化角色的子类，实现父类中的业务方法，并通过组合关系调用实现化角色中的业务方法。</span></li>
        <li><span>实现化（Implementor）角色 ：定义实现化角色的接口，供扩展抽象化角色调用。</span></li>
        <li><span>具体实现化（Concrete Implementor）角色 ：给出实现化角色接口的具体实现。</span></li>
    </ul>
    <p>&nbsp;</p>
    <h3><a name="543-案例" class="md-header-anchor"></a><span>5.4.3 案例</span></h3>
    <p><span>【例】视频播放器</span></p>
    <p>
        <span>需要开发一个跨平台视频播放器，可以在不同操作系统平台（如Windows、Mac、Linux等）上播放多种格式的视频文件，常见的视频格式包括RMVB、AVI、WMV等。该播放器包含了两个维度，适合使用桥接模式。</span>
    </p>
    <p><span>类图如下：</span></p>
    <p><img src="img\桥接模式.png" style="zoom:80%;"/></p>
    <p><span>代码如下：</span></p>
    <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="java" style="break-inside: unset;"><div
            class="CodeMirror cm-s-inner CodeMirror-wrap" lang="java"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 44px;"><textarea
            autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0"
            style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler"
                                                                                                                                     cm-not-content="true"></div><div
            class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer"
                                                                                                                           style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div
            style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div
            class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>63</div></div></div><div
            class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline"
                                                                                                                                                               style="position: relative;"><div
            class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter"
                                                                                          style="left: -36px; width: 36px;"></div><div
            class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                     style="left: 0px; width: 27px;">1</div></div><pre class=" CodeMirror-line "
                                                                                                                                                       role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//视频文件</span></span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span
            class="cm-keyword">interface</span> <span class="cm-def">VideoFile</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-variable-3">void</span> <span class="cm-variable">decode</span>(<span class="cm-variable-3">String</span> <span class="cm-variable">fileName</span>);</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                         style="left: 0px; width: 27px;">4</div></div><pre class=" CodeMirror-line "
                                                                                                                                                           role="presentation"><span
            role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"><span
            cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"><span
            class="cm-comment">//avi文件</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"><span
            class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span class="cm-def">AVIFile</span> <span class="cm-keyword">implements</span> <span class="cm-variable">VideoFile</span> {</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                         style="left: 0px; width: 27px;">8</div></div><pre class=" CodeMirror-line "
                                                                                                                                                           role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span class="cm-variable-3">void</span> <span
            class="cm-variable">decode</span>(<span class="cm-variable-3">String</span> <span class="cm-variable">fileName</span>) {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">System</span>.<span
            class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-string">"avi视频文件："</span><span class="cm-operator">+</span> <span class="cm-variable">fileName</span>);</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 27px;">10</div></div><pre class=" CodeMirror-line "
                                                                                                                                                            role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;">}</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">12</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">13</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//rmvb文件</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">14</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
            class="cm-def">REVBBFile</span> <span class="cm-keyword">implements</span> <span class="cm-variable">VideoFile</span> {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">15</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">16</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable-3">void</span> <span class="cm-variable">decode</span>(<span class="cm-variable-3">String</span> <span
            class="cm-variable">fileName</span>) {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">17</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-string">"rmvb文件："</span> <span
            class="cm-operator">+</span> <span class="cm-variable">fileName</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                             style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">18</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">19</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                        style="left: 0px; width: 27px;">20</div></div><pre class=" CodeMirror-line " role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">21</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            class="cm-comment">//操作系统版本</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">22</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            class="cm-keyword">public</span> <span class="cm-keyword">abstract</span> <span class="cm-keyword">class</span> <span class="cm-def">OperatingSystemVersion</span> {</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">23</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">24</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">protected</span> <span
            class="cm-variable">VideoFile</span> <span class="cm-variable">videoFile</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                     style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">25</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">26</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-variable">OperatingSystemVersion</span>(<span class="cm-variable">VideoFile</span> <span class="cm-variable">videoFile</span>) {</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">27</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">this</span>.<span
            class="cm-variable">videoFile</span> <span class="cm-operator">=</span> <span class="cm-variable">videoFile</span>;</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">28</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">29</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 27px;">30</div></div><pre class=" CodeMirror-line "
                                                                                                                                                            role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span class="cm-keyword">abstract</span> <span
            class="cm-variable-3">void</span> <span class="cm-variable">play</span>(<span class="cm-variable-3">String</span> <span class="cm-variable">fileName</span>);</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">31</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">32</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">33</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//Windows版本</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">34</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
            class="cm-def">Windows</span> <span class="cm-keyword">extends</span> <span class="cm-variable">OperatingSystem</span> {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">35</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">36</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable">Windows</span>(<span class="cm-variable">VideoFile</span> <span class="cm-variable">videoFile</span>) {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">37</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">super</span>(<span
            class="cm-variable">videoFile</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">38</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">39</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 27px;">40</div></div><pre class=" CodeMirror-line "
                                                                                                                                                            role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span class="cm-variable-3">void</span> <span
            class="cm-variable">play</span>(<span class="cm-variable-3">String</span> <span class="cm-variable">fileName</span>) {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">41</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">videoFile</span>.<span
            class="cm-variable">decode</span>(<span class="cm-variable">fileName</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                  style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">42</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">43</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">44</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">45</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//mac版本</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">46</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
            class="cm-def">Mac</span> <span class="cm-keyword">extends</span> <span class="cm-variable">OperatingSystemVersion</span> {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">47</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">48</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable">Mac</span>(<span class="cm-variable">VideoFile</span> <span class="cm-variable">videoFile</span>) {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">49</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">super</span>(<span
            class="cm-variable">videoFile</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">50</div></div><pre class=" CodeMirror-line "
                                                                                                                                              role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">51</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">52</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable-3">void</span> <span class="cm-variable">play</span>(<span class="cm-variable-3">String</span> <span class="cm-variable">fileName</span>) {</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">53</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text="	">    </span><span
            class="cm-tab" role="presentation" cm-text="	">    </span><span class="cm-variable">videoFile</span>.<span class="cm-variable">decode</span>(<span
            class="cm-variable">fileName</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">54</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">55</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">56</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">57</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//测试类</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">58</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
            class="cm-def">Client</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">59</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-keyword">static</span> <span class="cm-variable-3">void</span> <span class="cm-variable">main</span>(<span class="cm-variable-3">String</span>[] <span
            class="cm-variable">args</span>) {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">60</div></div><pre class=" CodeMirror-line "
                                                                                                                                              role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">OperatingSystem</span> <span class="cm-variable">os</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">Windows</span>(<span
            class="cm-keyword">new</span> <span class="cm-variable">AVIFile</span>());</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                               style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">61</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">os</span>.<span class="cm-variable">play</span>(<span class="cm-string">"战狼3"</span>);</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">62</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                        style="left: 0px; width: 27px;">63</div></div><pre class=" CodeMirror-line " role="presentation"><span
            role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div
            style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 1428px;"></div><div class="CodeMirror-gutters" style="height: 1428px;"><div
            class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div></div></div></div></pre>
    <p><strong><span>好处：</span></strong></p>
    <ul>
        <li><p><span>桥接模式提高了系统的可扩充性，在两个变化维度中任意扩展一个维度，都不需要修改原有系统。</span></p>
            <p><span>如：如果现在还有一种视频文件类型wmv，我们只需要再定义一个类实现VideoFile接口即可，其他类不需要发生变化。</span></p></li>
        <li><p><span>实现细节对客户透明</span></p></li>
    </ul>
    <h3><a name="544-使用场景" class="md-header-anchor"></a><span>5.4.4 使用场景</span></h3>
    <ul>
        <li><span>当一个类存在两个独立变化的维度，且这两个维度都需要进行扩展时。</span></li>
        <li><span>当一个系统不希望使用继承或因为多层次继承导致系统类的个数急剧增加时。</span></li>
        <li><span>当一个系统需要在构件的抽象化角色和具体化角色之间增加更多的灵活性时。避免在两个层次之间建立静态的继承联系，通过桥接模式可以使它们在抽象层建立一个关联关系。</span></li>
    </ul>
    <p>&nbsp;</p>
    <h2><a name="55-外观模式" class="md-header-anchor"></a><span>5.5 外观模式</span></h2>
    <h3><a name="551-概述" class="md-header-anchor"></a><span>5.5.1 概述</span></h3>
    <p>
        <span>有些人可能炒过股票，但其实大部分人都不太懂，这种没有足够了解证券知识的情况下做股票是很容易亏钱的，刚开始炒股肯定都会想，如果有个懂行的帮帮手就好，其实基金就是个好帮手，支付宝里就有许多的基金，它将投资者分散的资金集中起来，交由专业的经理人进行管理，投资于股票、债券、外汇等领域，而基金投资的收益归持有者所有，管理机构收取一定比例的托管管理费用。</span>
    </p>
    <p><strong><span>定义：</span></strong></p>
    <p>
        <span>	</span><span>又名门面模式，是一种通过为多个复杂的子系统提供一个一致的接口，而使这些子系统更加容易被访问的模式。该模式对外有一个统一接口，外部应用程序不用关心内部子系统的具体的细节，这样会大大降低应用程序的复杂度，提高了程序的可维护性。</span>
    </p>
    <p><span>	</span><span>外观（Facade）模式是“迪米特法则”的典型应用</span></p>
    <p><img src="img\外观模式引入.jpg" referrerpolicy="no-referrer"></p>
    <p>&nbsp;</p>
    <h3><a name="552-结构" class="md-header-anchor"></a><span>5.5.2 结构</span></h3>
    <p><span>外观（Facade）模式包含以下主要角色：</span></p>
    <ul>
        <li><span>外观（Facade）角色：为多个子系统对外提供一个共同的接口。</span></li>
        <li><span>子系统（Sub System）角色：实现系统的部分功能，客户可以通过外观角色访问它。</span></li>
    </ul>
    <p>&nbsp;</p>
    <h3><a name="553-案例" class="md-header-anchor"></a><span>5.5.3 案例</span></h3>
    <p><span>【例】智能家电控制</span></p>
    <p>
        <span>小明的爷爷已经60岁了，一个人在家生活：每次都需要打开灯、打开电视、打开空调；睡觉时关闭灯、关闭电视、关闭空调；操作起来都比较麻烦。所以小明给爷爷买了智能音箱，可以通过语音直接控制这些智能家电的开启和关闭。类图如下：</span>
    </p>
    <p><img src="img/外观模式.png" style="zoom:80%;"/></p>
    <p><span>代码如下：</span></p>
    <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="java" style="break-inside: unset;"><div
            class="CodeMirror cm-s-inner CodeMirror-wrap" lang="java"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 44px;"><textarea
            autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0"
            style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler"
                                                                                                                                     cm-not-content="true"></div><div
            class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer"
                                                                                                                           style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div
            style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div
            class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>83</div></div></div><div
            class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline"
                                                                                                                                                               style="position: relative;"><div
            class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter"
                                                                                          style="left: -36px; width: 36px;"></div><div
            class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                     style="left: 0px; width: 27px;">1</div></div><pre class=" CodeMirror-line "
                                                                                                                                                       role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//灯类</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                             style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"><span
            class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span class="cm-def">Light</span> {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable-3">void</span> <span class="cm-variable">on</span>() {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                              style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-string">"打开了灯...."</span>);</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"
                                                                                                         style="left: 0px; width: 27px;">5</div></div><pre class=" CodeMirror-line "
                                                                                                                                                           role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"><span
            cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                      style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-variable-3">void</span> <span class="cm-variable">off</span>() {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">8</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">System</span>.<span
            class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-string">"关闭了灯...."</span>);</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                        style="left: 0px; width: 27px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span
            role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            class="cm-comment">//电视类</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span class="cm-def">TV</span> {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">14</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable-3">void</span> <span class="cm-variable">on</span>() {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                              style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">15</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span
            class="cm-string">"打开了电视...."</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">16</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">17</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">18</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable-3">void</span> <span class="cm-variable">off</span>() {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                               style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">19</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span
            class="cm-string">"关闭了电视...."</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">20</div></div><pre class=" CodeMirror-line "
                                                                                                                                              role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">21</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">22</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">23</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//控制类</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">24</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
            class="cm-def">AirCondition</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">25</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-variable-3">void</span> <span class="cm-variable">on</span>() {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">26</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">System</span>.<span
            class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-string">"打开了空调...."</span>);</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">27</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">28</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">29</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable-3">void</span> <span class="cm-variable">off</span>() {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                               style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">30</div></div><pre class=" CodeMirror-line "
                                                                                                                                              role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span
            class="cm-string">"关闭了空调...."</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">31</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">32</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">33</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">34</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//智能音箱</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">35</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
            class="cm-def">SmartAppliancesFacade</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">36</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"><span
            cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">37</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">private</span> <span class="cm-variable">Light</span> <span class="cm-variable">light</span>;</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">38</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">private</span> <span
            class="cm-variable">TV</span> <span class="cm-variable">tv</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">39</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">private</span> <span class="cm-variable">AirCondition</span> <span class="cm-variable">airCondition</span>;</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                        style="left: 0px; width: 27px;">40</div></div><pre class=" CodeMirror-line " role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">41</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-variable">SmartAppliancesFacade</span>() {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">42</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">light</span> <span
            class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">Light</span>();</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">43</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">tv</span> <span
            class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">TV</span>();</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">44</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">airCondition</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span class="cm-variable">AirCondition</span>();</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">45</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">46</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">47</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">public</span> <span
            class="cm-variable-3">void</span> <span class="cm-variable">say</span>(<span class="cm-variable-3">String</span> <span class="cm-variable">message</span>) {</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">48</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-keyword">if</span>(<span
            class="cm-variable">message</span>.<span class="cm-variable">contains</span>(<span class="cm-string">"打开"</span>)) {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">49</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">on</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">50</div></div><pre class=" CodeMirror-line "
                                                                                                                                              role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  } <span
            class="cm-keyword">else</span> <span class="cm-keyword">if</span>(<span class="cm-variable">message</span>.<span class="cm-variable">contains</span>(<span
            class="cm-string">"关闭"</span>)) {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">51</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">off</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">52</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  } <span
            class="cm-keyword">else</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">53</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span
            class="cm-string">"我还听不懂你说的！！！"</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">54</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">55</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">56</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">57</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-comment">//起床后一键开电器</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">58</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">private</span> <span class="cm-variable-3">void</span> <span class="cm-variable">on</span>() {</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">59</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">System</span>.<span
            class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-string">"起床了"</span>);</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                        style="left: 0px; width: 27px;">60</div></div><pre class=" CodeMirror-line " role="presentation"><span
            role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">light</span>.<span class="cm-variable">on</span>();</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">61</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">tv</span>.<span
            class="cm-variable">on</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">62</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">airCondition</span>.<span class="cm-variable">on</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                   style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">63</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">64</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">65</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-comment">//睡觉一键关电器</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">66</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp;<span class="cm-keyword">private</span> <span
            class="cm-variable-3">void</span> <span class="cm-variable">off</span>() {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                               style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">67</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">System</span>.<span class="cm-variable">out</span>.<span class="cm-variable">println</span>(<span class="cm-string">"睡觉了"</span>);</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">68</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">light</span>.<span
            class="cm-variable">off</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">69</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">tv</span>.<span class="cm-variable">off</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                          style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">70</div></div><pre class=" CodeMirror-line "
                                                                                                                                              role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">airCondition</span>.<span class="cm-variable">off</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                                    style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">71</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">72</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">73</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">74</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//测试类</span></span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">75</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">public</span> <span class="cm-keyword">class</span> <span
            class="cm-def">Client</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">76</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp;<span
            class="cm-keyword">public</span> <span class="cm-keyword">static</span> <span class="cm-variable-3">void</span> <span class="cm-variable">main</span>(<span class="cm-variable-3">String</span>[] <span
            class="cm-variable">args</span>) {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">77</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">//创建外观对象</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">78</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">SmartAppliancesFacade</span> <span class="cm-variable">facade</span> <span class="cm-operator">=</span> <span class="cm-keyword">new</span> <span
            class="cm-variable">SmartAppliancesFacade</span>();</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">79</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-comment">//客户端直接与外观对象进行交互</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 27px;">80</div></div><pre class=" CodeMirror-line "
                                                                                                                                              role="presentation"><span role="presentation"
                                                                                                                                                                        style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span
            class="cm-variable">facade</span>.<span class="cm-variable">say</span>(<span class="cm-string">"打开家电"</span>);</span></pre></div><div style="position: relative;"><div
            class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">81</div></div><pre
            class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="cm-variable">facade</span>.<span
            class="cm-variable">say</span>(<span class="cm-string">"关闭家电"</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper"
                                                                                                                                               style="left: -36px;"><div
            class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">82</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation"
                                                                                                                                                                       style="padding-right: 0.1px;"> &nbsp;  }</span></pre></div><div
            style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -36px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show"
                                                                                                         style="left: 0px; width: 27px;">83</div></div><pre class=" CodeMirror-line "
                                                                                                                                                            role="presentation"><span
            role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div
            style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 1881px;"></div><div class="CodeMirror-gutters" style="height: 1881px;"><div
            class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div></div></div></div></pre>
    <p><strong><span>好处：</span></strong></p>
    <ul>
        <li><span>降低了子系统与客户端之间的耦合度，使得子系统的变化不会影响调用它的客户类。</span></li>
        <li><span>对客户屏蔽了子系统组件，减少了客户处理的对象数目，并使得子系统使用起来更加容易。</span></li>
    </ul>
    <p><strong><span>缺点：</span></strong></p>
    <ul>
        <li><span>不符合开闭原则，修改很麻烦</span></li>
    </ul>
    <p>&nbsp;</p>
    <h3><a name="554-使用场景" class="md-header-anchor"></a><span>5.5.4 使用场景</span></h3>
    <ul>
        <li><span>对分层结构系统构建时，使用外观模式定义子系统中每层的入口点可以简化子系统之间的依赖关系。</span></li>
        <li><span>当一个复杂系统的子系统很多时，外观模式可以为系统设计一个简单的接口供外界访问。</span></li>
        <li><span>当客户端与多个子系统之间存在很大的联系时，引入外观模式可将它们分离，从而提高子系统的独立性和可移植性。</span></li>
    </ul>
    <p>&nbsp;</p>
    <h3><a name="555-源码解析" class="md-header-anchor"></a><span>5.5.5 源码解析</span></h3>
    <p><span>使用tomcat作为web容器时，接收浏览器发送过来的请求，tomcat会将请求信息封装成ServletRequest对象，如下图①处对象。但是大家想想ServletRequest是一个接口，它还有一个子接口HttpServletRequest，而我们知道该request对象肯定是一个HttpServletRequest对象的子实现类对象，到底是哪个类的对象呢？可以通过输出request对象，我们就会发现是一个名为RequestFacade的类的对象。</span>
    </p>
    <p><img src="img/image-20200207234545691.png" style="zoom:60%;"/></p>
    <p><span>RequestFacade类就使用了外观模式。先看结构图：</span></p>
    <p><img src="img/外观模式-jdk源码解析.png" style="zoom:70%;"/></p>
    <p><strong><span>为什么在此处使用外观模式呢？</span></strong></p>
    <p><span>	</span><span>定义 RequestFacade 类，分别实现 ServletRequest ，同时定义私有成员变量 Request ，并且方法的实现调用 Request  的实现。然后，将 RequestFacade上转为 ServletRequest  传给 servlet 的 service 方法，这样即使在 servlet 中被下转为 RequestFacade ，也不能访问私有成员变量对象中的方法。既用了 Request ，又能防止其中方法被不合理的访问。</span>
    </p>
    <p>&nbsp;</p></div>
</body>
</html>